1
0
Fork 0
mirror of synced 2024-06-10 06:34:33 +12:00

Added a check to make sure results were found

This commit is contained in:
Phxntxm 2016-10-29 16:39:37 -05:00
parent 7d5b51bb6e
commit 6445a8ae17

View file

@ -51,7 +51,11 @@ class Links:
for element in soup.find_all('h3', class_='r')[:3]:
# Get the link's href tag, which looks like q=[url here]&sa
# Use a lookahead and lookbehind to find this url exactly
result_url = re.search('(?<=q=).*(?=&sa=)', element.find('a').get('href')).group(0)
try:
result_url = re.search('(?<=q=).*(?=&sa=)', element.find('a').get('href')).group(0)
except AttributeError:
await self.bot.say("I couldn't find any results for {}!".format(query))
return
# Get the next sibling, find the span where the description is, and get the text from this
try: