def drug_wiki(_input): a=0 if _input['cmd']=='chat' and len(_input['text'].strip())>7 and '`drug ' in _input['text']: _input=_input['text'] term=_input[6::] encoded_search = urllib.parse.quote(term) print(encoded_search) url='http://psychonaut3z5aoz.onion/w/index.php?search='+encoded_search+"&redirect=no" req = urllib.request.Request(url) response = urllib.request.urlopen(req) output=bs(response,'html.parser') _result=[] for drug in output.select(".mw-search-result-heading"): if a<1: if drug["href"].startswith("/"): a+=1 drug_info = {"title": drug["title"], "link": drug["href"]} title=drug_info['title'] link=drug_info['link'] url=title+':\n'+'* http://psychonaut3z5aoz.onion'+link _send_msg(url)