From 6445a8ae17c950ae99ccd911dd461a98c2d838c2 Mon Sep 17 00:00:00 2001 From: Phxntxm Date: Sat, 29 Oct 2016 16:39:37 -0500 Subject: [PATCH] Added a check to make sure results were found --- cogs/links.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cogs/links.py b/cogs/links.py index 0938720..63476ce 100644 --- a/cogs/links.py +++ b/cogs/links.py @@ -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: