Skip to content

Instantly share code, notes, and snippets.

@rvvvt
Forked from yxlao/google_search_bs.py
Created January 18, 2019 15:54
Show Gist options
  • Save rvvvt/c1bc3b19e6f7112c5eaa964c835d273e to your computer and use it in GitHub Desktop.
Save rvvvt/c1bc3b19e6f7112c5eaa964c835d273e to your computer and use it in GitHub Desktop.
Google search with BeautifulSoup
import requests
from bs4 import BeautifulSoup
search_url_prefix = "https://www.google.com/search?q="
def get_first_result(search_str):
search_url = search_url_prefix + search_str
r = requests.get(search_url)
soup = BeautifulSoup(r.text, "html.parser")
return soup.find('cite').text
companies = ['Google', 'Microsoft']
for company in companies:
result = get_first_result(company)
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment