Last active
April 2, 2017 22:16
-
-
Save Krewn/e886ab9356c32e4dbcd2c642f2061798 to your computer and use it in GitHub Desktop.
Krewn Google Spell Check: W/ Mechanize Browser Emulation and BeautifulSoup.
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 mechanize | |
import BeautifulSoup | |
def chill(): | |
return | |
def googleSpellCheck(word , supervised = False): | |
ret = word | |
chrome = mechanize.Browser() | |
chrome.set_handle_robots(False) | |
chrome.addheaders = [('User-agent', '')] | |
htmltext = chrome.open("https://www.google.com/search?q=spell%20"+word).read() | |
soup = BeautifulSoup.BeautifulSoup(htmltext) | |
hit = soup.find("b",{}) | |
try: | |
ret = hit.find("i", {}).contents[0].strip() | |
except AttributeError: | |
chill() | |
if supervised: | |
if ret!=word: | |
prompt = input("found:'"+word+"', did you mean '"+ret+"'?") | |
if len(set("Nn").intersection(set(promt))): | |
ret = word | |
return(ret) | |
print googleSpellCheck("watsun") | |
#prints watson |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment