-2

Is there a quick way to search Google for a pair of string (like 'married life' and 'happy living' ) and the return the number of results? I can manually do that but I have huge list of words , would love to know if there's a better way.

  • 1
    Quite a few results for "google python number of results" – vaultah Nov 04 '15 at 13:52
  • @vaultah but how would you find out how many, using Python? – jonrsharpe Nov 04 '15 at 13:54
  • 1
    Some of those results: [1](http://stackoverflow.com/q/4785833/2301450), [2](http://stackoverflow.com/questions/29377504/perform-a-google-search-and-return-the-number-of-results), [3](http://stackoverflow.com/q/3334122/2301450) @jonrsharpe – vaultah Nov 04 '15 at 13:57
  • @vaultah ...that was a joke! – jonrsharpe Nov 04 '15 at 13:58
  • In my Python installation, there is a file "Google.py" (I must admit, I am working with Python 3.4). In case you have this library too, I'd propose you to try to use it and to parse the result in your webbrowser. (don't kill me if you don't have this library :-) ) – Dominique Nov 04 '15 at 14:15
  • Found one script ..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 – user1405838 Nov 04 '15 at 14:31
  • But it works for single word not string.. can you help me out @vaultah – user1405838 Nov 04 '15 at 14:33

1 Answers1

5

You can use the following code:

import requests
from bs4 import BeautifulSoup

search = "django framework"

r = requests.get("https://www.google.com/search", params={'q':search})

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

Output:

About 10,400,000 results

Additional: If you want the exact number then you can use the following line below:

print int(res.text.replace(",", "").split()[1])

Output:

10400000
JRodDynamite
  • 12,325
  • 5
  • 43
  • 63
  • 1
    the problem is that google bans you after X amount of requests. Is there any way to do this without getting banned – taga Mar 20 '20 at 23:39