Selaa lähdekoodia

bin/ircd: try/except getting title text

Dastan-glitch 3 vuotta sitten
vanhempi
sitoutus
6828d720f4
1 muutettua tiedostoa jossa 4 lisäystä ja 3 poistoa
  1. 4 3
      bin/ircd/script/bots/titlebot.py

+ 4 - 3
bin/ircd/script/bots/titlebot.py

@@ -27,13 +27,14 @@ while True:
 
         for i in url:
             parsed_url = urlparse(i)
-            if parsed_url.netloc.lower() in ['twitter.com','t.co'] and parsed_url.scheme != 'https':
+            if parsed_url.netloc.lower() in ['twitter.com','t.co'] or parsed_url.scheme != 'https':
                 continue
             reqs = requests.get(i)
             soup = BeautifulSoup(reqs.text, 'html.parser')
 
-            title_text = soup.find('title').get_text()
-            if not len(title_text) > 0:
+            try:
+                title_text = soup.find('title').get_text()
+            except:
                 print("Error: Title not found!")
                 continue
             title_text = title_text.split('\n')