urlinfo: fix some NoneType attribute errors

This commit is contained in:
jkhsjdhjs 2021-07-20 21:40:38 +00:00
parent fe79f444cf
commit ceb3002281

View File

@ -44,7 +44,18 @@ class URLInfo(Plugin):
bytes_io.seek(0)
tree = etree.parse(bytes_io, etree.HTMLParser()).getroot()
title_elements = tree.xpath("/html/head/title")
if len(title_elements) > 0:
self.bot.privmsg(target, '\x02[URLInfo]\x02 ' + title_elements[0].text.strip())
if tree is None:
return
title_elements = tree.xpath("/html/head/title")
if len(title_elements) == 0:
return
title = title_elements[0].text
if title is None:
return
title = title.strip()
if title:
self.bot.privmsg(target, '\x02[URLInfo]\x02 ' + title)