perform a google search and return the number of results

前端 未结 1 676
走了就别回头了
走了就别回头了 2020-12-19 05:39

The Google Web Search APIs appear to be dead (both the old SOAP and the newer AJAX). Is there a quick way to search Google for a string and return the number of results? I

相关标签:
1条回答
  • 2020-12-19 06:17

    There is still a free API, but here is a screen-scraper:

    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
    

    Results:

    $ 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
    
    0 讨论(0)
提交回复
热议问题