Skip to content

Instantly share code, notes, and snippets.

@000hen
Last active September 16, 2021 10:51
Show Gist options
  • Select an option

  • Save 000hen/ea92eafc858d94674f5984ab943eccfb to your computer and use it in GitHub Desktop.

Select an option

Save 000hen/ea92eafc858d94674f5984ab943eccfb to your computer and use it in GitHub Desktop.
Google Fetcher
# !!Install BeautifulSoup, Requests First!!
import requests as rs
import sys
import json
from bs4 import BeautifulSoup
from urllib.parse import parse_qs, urlparse
search = [
# String of what you want to search
]
respond = []
for t in search:
dt = rs.get("https://www.google.com/search?q={}".format(t))
respond.append({
"query": t,
"respond": dt.text
})
fg = []
for g in respond:
dt = g["respond"]
soup = BeautifulSoup(dt, 'html.parser')
title = soup.find_all(class_="BNeawe vvjwJb AP7Wnd")
desc = soup.find_all(class_="BNeawe s3v9rd AP7Wnd")
descG = []
for i in desc:
try:
descG.append(i.findChildren(class_="BNeawe s3v9rd AP7Wnd")[0].text)
except:
i = None
for i in range(len(title)):
try:
url = title[i].parent.parent["href"]
desc = descG[i]
urlP = urlparse("http://example.com{}".format(url)).query
urlP = parse_qs(urlP, keep_blank_values=True)
print("---------------")
print("I caughted: {}, \n\nContent:\n{}, \n\nURL: \n{}".format(title[i].text, desc, urlP["q"][0]))
print("---------------")
fg.append({
"searchQuery": g["query"],
"searchTitle": title[i].text,
"searchDescription": desc,
"searchSiteURL": urlP["q"][0],
"searchURL": "https://www.google.com/search?q={}".format(g["query"])
})
except:
i = None
f = open("search.json", "w", encoding="utf-8")
f.write(json.dumps(fg))
f.close()
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment