Skip to content

Instantly share code, notes, and snippets.

@yxlao
Last active January 18, 2019 15:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yxlao/ad429b65ec1b3836da8f06fbd9fa8c54 to your computer and use it in GitHub Desktop.
Save yxlao/ad429b65ec1b3836da8f06fbd9fa8c54 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