Created
March 13, 2017 02:34
Star
You must be signed in to star a gist
Get number of search results from Google
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_n_results_dumb(q): | |
r = requests.get('http://www.google.com/search', | |
params={'q': q, | |
"tbs": "li:1"}) | |
r.raise_for_status() | |
soup = bs4.BeautifulSoup(r.text) | |
s = soup.find('div', {'id': 'resultStats'}).text | |
if not s: | |
return 0 | |
m = re.search(r'([0-9,]+)', s) | |
return int(m.groups()[0].replace(',', '')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment