def wiki_lookup(self): wiki = twill.commands out = StringIO() twill.set_output(out) res = wiki.go('http://en.wikipedia.org/wiki/Main_Page') res = wiki.formvalue(1, "searchInput", self.name) res = wiki.tidy_ok() res = wiki.submit(0) data = (wiki.get_browser().get_html()) out = open('tmp', 'a') i = 0 go = False for line in data.split('\n'): soep = BeautifulSoup(line) for line in soep.popTag(): try: for div in line.findAll('div').pop(): if (div.encode().strip().startswith('may refer to:')): desc = str(line.findAll('div')[0]).split( '>')[13].split('<')[0].strip() link = str(line.findAll('a')[0]).replace( '/wiki/', 'http://en.wikipedia.org/wiki/') return (desc, link) except: pass return (False)