URL title is content type header for non HTML responses.

This commit is contained in:
Jonathan Harker 2015-11-24 10:09:48 +13:00
parent bf2da99ce6
commit eb3c2fc398

View file

@ -68,8 +68,11 @@ class Url(Model):
if title is None: if title is None:
r = requests.get(url) r = requests.get(url)
if r.status_code == 200: if r.status_code == 200:
dom = BeautifulSoup(r.content, 'html.parser') if 'text/html' in r.headers['content-type']:
self.title = dom.title.string dom = BeautifulSoup(r.content, 'html.parser')
self.title = dom.title.string
else:
self.title = r.headers['content-type']
else: else:
self.title = "Error: HTTP %s" % r.status_code self.title = "Error: HTTP %s" % r.status_code