Handle <title>s with key="value"s
This commit is contained in:
parent
6fff4f207c
commit
9b27bc728f
11
botcmd.py
11
botcmd.py
|
@ -71,8 +71,14 @@ def extract_title(page_data):
|
||||||
if maybe_tag == -1: break
|
if maybe_tag == -1: break
|
||||||
maybe_tag += index
|
maybe_tag += index
|
||||||
|
|
||||||
if page_data[maybe_tag:maybe_tag+7].lower() == b'<title>':
|
if page_data[maybe_tag:maybe_tag+6].lower() == b'<title':
|
||||||
title_start = maybe_tag + 7
|
# Apparently <title> can have key="value" things
|
||||||
|
# Find the end of the tag
|
||||||
|
tag_closing = page_data[maybe_tag:].find(b'>')
|
||||||
|
if tag_closing != -1:
|
||||||
|
# It is relative to maybe_tag and we want
|
||||||
|
# the string after it
|
||||||
|
title_start = maybe_tag + tag_closing + 1
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
index = maybe_tag + 1
|
index = maybe_tag + 1
|
||||||
|
@ -104,6 +110,7 @@ def extract_title(page_data):
|
||||||
return title
|
return title
|
||||||
|
|
||||||
def sanitize(title):
|
def sanitize(title):
|
||||||
|
if title is None: return None
|
||||||
return ''.join('\ufffd' if ord(c) < 32 else c for c in title)
|
return ''.join('\ufffd' if ord(c) < 32 else c for c in title)
|
||||||
|
|
||||||
# handle_message(*, prefix, message, nick, channel, irc)
|
# handle_message(*, prefix, message, nick, channel, irc)
|
||||||
|
|
Loading…
Reference in New Issue