Skip to content

Instantly share code, notes, and snippets.

@Krewn
Last active April 2, 2017 22:16
Show Gist options
  • Save Krewn/e886ab9356c32e4dbcd2c642f2061798 to your computer and use it in GitHub Desktop.
Save Krewn/e886ab9356c32e4dbcd2c642f2061798 to your computer and use it in GitHub Desktop.
Krewn Google Spell Check: W/ Mechanize Browser Emulation and BeautifulSoup.
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