Created
September 11, 2019 04:12
-
-
Save hkamran80/ce08b2212dc4e3490a2c59473dc2ef24 to your computer and use it in GitHub Desktop.
Simple Google Search in Python
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
from bs4 import BeautifulSoup | |
import requests | |
url = "https://google.com/search?q=python" | |
headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.1 Safari/605.1.15"} | |
r = requests.get(url, headers=headers) | |
print(r.status_code) | |
page = BeautifulSoup(r.content, "html.parser") | |
results = [] | |
for result in page.select("h3.r"): | |
results.append(result.text.strip()) | |
print(results) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment