I'm fairly new to php. I was attempting to create a php script to automate one of my tasks which i perform regularly, which involved getting some information from a google search query. For example, the query looks like this: http://www.google.co.uk/search?hl=en&q=my+search+term&btnG=Google+Search&meta= and I would replace the "my+search+term" above with whatever i needed (this was done in the php script). So, after figuring out how to code the php, I finally got this program to work yesterday. I was using file_get_contents($url, 0); PHP: Today i was working on it a bit more, then, all of a sudden, I started getting this error: Warning: file_get_contents(): HTTP request failed! HTTP/1.0 503 Service Unavailable in /home/content/t/r/o/mySite/html/phpWork/phpWork.php on line 90 Warning: file_get_contents(http://www.google.com/search?hl=en&q=candy+canes&btnG=Search): failed to open stream: Success in /home/content/t/r/o/tropical6/mySite/phpWork/phpWork.php on line 90 Is it possible that google is not allowing me to access their search results through my php script? I am confused because it was working perfectly! and now it doesnt work... very frustrating! Why would it work just a little while ago and not any more? Any suggestions or tips or ideas would be greatly appreciated. Thanks in advance.
It was working though!! perfectly!! I tried curl, when i use curl, it tells me clearly that "it looks like an automated script that might be a virus or spyware so..." so CURL doesnt work either! I dont understand because IT WAS WORKING just fine with file_get_contents
Why not code something that add referrer and delay to your script? So, google will look at your query like it came from human and not from automated script.
Google will temporarily block requests from sources making numerous requests in a short period of time, or making the same request numerous times in a row. For testing, save a copy of a result page on your server and point file_get_contents at that instead.
You add to need useragent to curlopt to make it look like as a request coming from a web browser. A simple curl command wont work.
Try the Obolynx Google Search Script here: http://obolynx.com/forums/php/5553-obolynx-google-search-script-get-google-search-results.html