Perform a Google search and return the number of results

The Google Web Search API API seems dead (both old SOAP and new AJAX). Is there a quick way to search google for a string and return the number of results? I guess I just need to run a search and clear the results, but I would like to know if there is a better way.

Update: it turns out that any automated access to Google that does not use its new API https://developers.google.com/custom-search/json-api/v1/overview violates their terms of service, and therefore is not recommended.

+4
source share
1 answer

API, -:

import requests
from bs4 import BeautifulSoup
import argparse

parser = argparse.ArgumentParser(description='Get Google Count.')
parser.add_argument('word', help='word to count')
args = parser.parse_args()

r = requests.get('http://www.google.com/search',
                 params={'q':'"'+args.word+'"',
                         "tbs":"li:1"}
                )

soup = BeautifulSoup(r.text)
print soup.find('div',{'id':'resultStats'}).text

:

$ python g.py jones
About 223,000,000 results
$ python g.py smith
About 325,000,000 results
$ python g.py 'smith and jones'
About 54,200,000 results
$ python g.py 'alias smith and jones'
About 181,000 results
+7

All Articles