Last active
January 18, 2019 15:54
Google search with BeautifulSoup
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
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