-
-
Save rvvvt/c1bc3b19e6f7112c5eaa964c835d273e to your computer and use it in GitHub Desktop.
Google search with BeautifulSoup
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
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