Skip to content

Instantly share code, notes, and snippets.

@parthpower
Last active April 3, 2017 17:54
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 parthpower/9583a3062ec94e8eb2e2 to your computer and use it in GitHub Desktop.
Save parthpower/9583a3062ec94e8eb2e2 to your computer and use it in GitHub Desktop.
Grabs Definition section from Google search result!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! It works actually!
import requests
import BeautifulSoup
from sys import argv
word = "tied"
if __name__ == "__main__":
if len(argv)>2:
word = argv[1]
data = requests.get("https://www.google.com/search?q=definition+%s"%word)
dom = BeautifulSoup.BeautifulSoup(data.text.encode("utf-8"))
fp = open("D:/originalPage.html","w")
fp.write(data.text.encode("utf-8"))
fp.close()
print("####SOUPS####")
results= dom.findAll("li",{"class":"g"})
for result in results:
if len(result.contents) == 1:
m = result.renderContents()
fp = open("D:/parsed.html","w")
fp.write("<html>")
fp.write(m)
fp.write("</html>")
fp.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment