PHP file_get_contents returns other web page than I see in my browser

匆匆过客 提交于 2019-12-24 17:13:18

问题


I'm trying to load a website into a variable. But if I run my code, it returns an other page than I see in my browser.

Here's my code:

$query = $_GET['q'];
$url = 'https://www.google.com/search?q='.str_replace(' ','+',$query);
$doc = file_get_contents($url, false, $context);
echo $doc;

I see a (I guess older and) other version of Google in my website then when I go to Google's website itsself.

Can anyone help me?

Edit

Here are some screenshots: This is my websiteThis is Google

To be more obviously, I want to scrape Google results. But with the file_get_contents function I get strange classes, where I get on the web (https://www.google.com) I see h3-tags.

来源:https://stackoverflow.com/questions/59407885/php-file-get-contents-returns-other-web-page-than-i-see-in-my-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!