我正在使用Python 3.2.3本规范上使用字符串模式html对象从特定的url获取html代码。错误:使用的findall</p> <pre><code>regex = '<title>(.+?)</title>' pattern = re.compile(regex) </code></pre> <p>,然后搜索模式:</p> <pre><code>titles = re.findall(pattern,html) print(titles) </code></pre> <p>不能像一个字节对象
html = response.read()
我得到错误“无法在字节状对象上使用字符串模式”。我曾尝试使用:
regex = b'<title>(.+?)</title>'
但附加一个“b”我的结果?谢谢。
什么是'html'和[你为什么使用正则表达式来解析HTML?](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-标签/ 1732454#1732454) –
什么是html对象?尝试使用'str(html)'。怎么了? – slezica
您推荐Ignacio的Python的哪个HTML解析器? – Nikhil