Created
March 13, 2017 02:34
-
-
Save erikbern/7e10efd98e93af94445e250c6d8d2bd0 to your computer and use it in GitHub Desktop.
Get number of search results from Google
This file contains hidden or 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