Last active
April 3, 2017 17:54
-
-
Save parthpower/9583a3062ec94e8eb2e2 to your computer and use it in GitHub Desktop.
Grabs Definition section from Google search result!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! It works actually!
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
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