- 使用xpath遇到 Unicode strings with encoding declaration are not supported. Please use bytes input or XML fragments without declaration.的问题解决方法
- 在使用下etree.HTML时有时候会出现这样的问题
- 代码如下
response = response.content.decode()
html = etree.HTML(response)
- 可以将代码更改一下,可解决此类问题
- 更改为:
response = response.content.decode()
html = bytes(bytearray(response, encoding='utf-8'))
html = etree.HTML(html)
url_list = html.xpath("//div[@id='main']//ul//a/@href")