def google(message, keywords):
"""
google ??????????
https://github.com/llimllib/limbo/blob/master/limbo/plugins/google.py
"""
if keywords == 'help':
return
query = quote(keywords)
url = "https://encrypted.google.com/search?q={0}".format(query)
soup = BeautifulSoup(requests.get(url).text, "html.parser")
answer = soup.findAll("h3", attrs={"class": "r"})
if not answer:
botsend(message, "`{}` ???????????????".format(keywords))
try:
_, url = answer[0].a['href'].split('=', 1)
url, _ = url.split('&', 1)
botsend(message, unquote(url))
except IndexError:
# in this case there is a first answer without a link, which is a
# google response! Let's grab it and display it to the user.
return ' '.join(answer[0].stripped_strings)
评论列表
文章目录