Skip to content

Python program that surfs 3 site at a time #1389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Oct 18, 2019
Merged
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
beautifulsoup4
black
fake_useragent
flake8
matplotlib
mypy
Expand Down
20 changes: 20 additions & 0 deletions web_programming/crawl_google_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import sys
import webbrowser

from bs4 import BeautifulSoup
from fake_useragent import UserAgent
import requests

print("Googling.....")
url = "https://www.google.com/search?q=" + " ".join(sys.argv[1:])
res = requests.get(url, headers={"UserAgent": UserAgent().random})
# res.raise_for_status()
with open("project1a.html", "wb") as out_file: # only for knowing the class
for data in res.iter_content(10000):
out_file.write(data)
soup = BeautifulSoup(res.text, "html.parser")
links = list(soup.select(".eZt8xd"))[:5]

print(len(links))
for link in links:
webbrowser.open(f"http://google.com{link.get('href')}")