mirror of https://github.com/stijndcl/didier
Add comments
parent
83f28d9e21
commit
652238ce55
|
@ -24,11 +24,9 @@ class Google(commands.Cog):
|
|||
if results is None:
|
||||
return await ctx.send("Er ging iets fout (Response {})".format(status))
|
||||
|
||||
# Filter out all Nones
|
||||
elements = list(filter(lambda x: x is not None, results))
|
||||
|
||||
if len(elements) > 10:
|
||||
elements = elements[:10]
|
||||
|
||||
embed = discord.Embed(colour=discord.Colour.blue())
|
||||
embed.set_author(name="Google Search")
|
||||
|
||||
|
@ -37,6 +35,10 @@ class Google(commands.Cog):
|
|||
embed.description = "Geen resultaten gevonden."
|
||||
return await ctx.reply(embed=embed, mention_author=False)
|
||||
|
||||
# Cut excess results out
|
||||
if len(elements) > 10:
|
||||
elements = elements[:10]
|
||||
|
||||
links = []
|
||||
|
||||
for index, (link, title) in enumerate(elements):
|
||||
|
|
|
@ -24,8 +24,12 @@ def google_search(query):
|
|||
bs = BeautifulSoup(resp.text, "html.parser")
|
||||
|
||||
def getContent(element):
|
||||
"""
|
||||
Function to find links & titles in the HTML of a <div> element
|
||||
"""
|
||||
link = element.find("a", href=True)
|
||||
title = element.find("h3")
|
||||
|
||||
if link is None or title is None:
|
||||
return None
|
||||
|
||||
|
@ -35,6 +39,7 @@ def google_search(query):
|
|||
return None
|
||||
|
||||
return link["href"], sp.text
|
||||
|
||||
divs = bs.find_all("div", attrs={"class": "g"})
|
||||
|
||||
return list(getContent(d) for d in divs), 200
|
||||
|
|
Loading…
Reference in New Issue