python - perform a google search and return the number of results -
the google web search apis appear dead (both old soap , newer ajax). there quick way search google string , return number of results? assume have run search , scrape results, i'd love know if there's better way.
update: turns out automated access google doesn't use new api https://developers.google.com/custom-search/json-api/v1/overview violates terms of service, , not recommended.
there still a free api, here screen-scraper:
import requests bs4 import beautifulsoup import argparse parser = argparse.argumentparser(description='get google count.') parser.add_argument('word', help='word 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 results:
$ python g.py jones 223,000,000 results $ python g.py smith 325,000,000 results $ python g.py 'smith , jones' 54,200,000 results $ python g.py 'alias smith , jones' 181,000 results
Comments
Post a Comment