Skip to content

Instantly share code, notes, and snippets.

@hkamran80
Created September 11, 2019 04:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hkamran80/ce08b2212dc4e3490a2c59473dc2ef24 to your computer and use it in GitHub Desktop.
Save hkamran80/ce08b2212dc4e3490a2c59473dc2ef24 to your computer and use it in GitHub Desktop.
Simple Google Search in Python
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