Forum Moderators: coopster

Message Too Old, No Replies

Gather total number of Google results?

         

mulligansrun

7:14 pm on Dec 8, 2007 (gmt 0)

10+ Year Member



I'm looking for something that can tell me the total number of results for X number of words.

Basically I need something that I can input a string of words into, one on each line (words will be in many different languages) and will return the total number of results for each word.

I just need the number from the bit at the top of the google results page .. the bit that says 'Results 1 - 10 of about 73,100,000 for "words"'

I just need the number .. 73,100,000
So the output would look like:

words 73,100,000
españa 67,800,000
адресная 1,560,000
大坂山 19,800

(Bearing in mind I will mainly be checking for results in languages like Chinese, Korean, Hindi, Spanish etc)

The number would have to reflect the total number of results within "double quotes" for an accurate reflection of the total.

Just a simple script, something I can run from my browser, maybe a desktop app or run from a server?
Doesn't have to save the results, I can just copy and paste them.

Anybody know of such a thing?

gergoe

8:13 pm on Dec 8, 2007 (gmt 0)

10+ Year Member



With the following function you can get the number you want, you only need to make a surrounding code to call this function. It connects to the google servers, sends a normal http query, reads the response, and parses the response with regular expressions to get the number you want. Please note that if google changes the results pages, this function needs to be adjusted.

function getWordCount($word) {
//
// Connect and send request. If can't connect, return false

if (($h = fsockopen('www.google.com', 80))!== false) {
fwrite($h,"GET /search?hl=en&q=%22". urlencode($word) ."%22 HTTP/1.1\r\n");
fwrite($h,"Connection: close\r\n");
fwrite($h,"Host: www.google.com\r\n\r\n");
//
// Read response

$response = '';
while (!feof($h)) $response .= fread($h, 8096);
fclose($h);
//
// Remove html

$text = preg_replace('¦</?.+?>¦', '', $response);
//
// Get count. If not found, return false

if (preg_match('¦Results \d+ - \d+ of about ([\d,]+) for¦', $text, $found)) {
return str_replace(',', '', $found[1]);
} else return false;
} else return false;
}