Merge pull request #89 from tswfi/fix_url_none

make sure title exists before trying to use it, fixes #83
This commit is contained in:
Ville Ranki 2020-06-18 14:43:24 +03:00 committed by GitHub
commit 69c18070f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -114,7 +114,8 @@ class MatrixModule(BotModule):
# try parse and get the title # try parse and get the title
try: try:
soup = BeautifulSoup(r.text, "html.parser") soup = BeautifulSoup(r.text, "html.parser")
title = soup.title.string.strip() if soup.head and soup.head.title:
title = soup.head.title.string.strip()
descr_tag = soup.find("meta", attrs={"name": "description"}) descr_tag = soup.find("meta", attrs={"name": "description"})
if descr_tag: if descr_tag:
description = descr_tag.get("content", None) description = descr_tag.get("content", None)