【发布时间】:2014-09-21 07:01:57
【问题描述】:
我正在尝试使用像here 提供的 HTML 抓取工具。它适用于他们提供的示例。但是,当我尝试将它与 webpage 一起使用时,我收到此错误 - Unicode strings with encoding declaration are not supported. Please use bytes input or XML fragments without declaration.
我试过谷歌搜索,但找不到解决方案。我真的很感激任何帮助。我想知道是否有办法使用 Python 将其复制为 HTML。
编辑:
from lxml import html
import requests
page = requests.get('http://cancer.sanger.ac.uk/cosmic/gene/analysis?ln=PTEN&ln1=PTEN&start=130&end=140&coords=bp%3AAA&sn=&ss=&hn=&sh=&id=15#')
tree = html.fromstring(page.text)
谢谢。
【问题讨论】:
-
请将您的抓取工具减少到仍然显示错误的最小程序,并将该短程序复制粘贴到您的问题中。请参阅stackoverflow.com/help/mcve 了解更多信息。
-
@Robᵩ 我已经添加了代码,但错误仍然相同:不支持带有编码声明的 Unicode 字符串。请使用未声明的字节输入或 XML 片段。
标签: python html unicode web-scraping lxml