Get amount of results for a website using google

78 views Asked by At

i was using this piece of code to get amount of google results

$dom = new DOMDocument();
$in = urlencode($term);
@$dom->loadHTMLFile('http://www.google.com/search?hl=en&tbo=d&site=&source=hp&q="'.$in.'"');
$xpath = new DOMXPath($dom);

$total = $xpath->query('//*[@id="resultStats"]')->item(0)->nodeValue;
$total = preg_replace("/[^0-9]/", "", $total);

But suddenly stopped working... and i can't fetch the url from server

Any ideas?

Thanks in advance

1

There are 1 answers

0
ptkoz On BEST ANSWER

Google sometimes blocks "unusual" trafiic and displays captcha to prove you're not a robot. This may have affected your script. See: https://support.google.com/websearch/answer/86640?hl=en