gpt4 book ai didi

python - 如何修复 "Unicode strings with encoding declaration are not supported."

转载 作者:行者123 更新时间:2023-12-02 07:33:02 25 4
gpt4 key购买 nike

ValueError: Unicode strings with encoding declaration are not supported. 
Please use bytes input or XML fragments without declaration.

当我尝试解析此网站时不起作用。

当我尝试序列化此页面文本时,出现错误类型错误:类型“str”无法序列化

from lxml import html

source = 'http://games.chruker.dk/eve_online/item.php?type_id=814'
path = '//*[@id="top"]/table[1]/tbody/tr[1]/td[3]/table'

page = requests.get(source)
pagetext = page.text

parser = html.fromstring(pagetext)

result = parser.xpath(path)
print(result)


我希望有一个表格要求,例如网站中的要求: http://games.chruker.dk/eve_online/item.php?type_id=814

最佳答案

试试这个:

parser = html.fromstring(bytes(pagetext, encoding='utf8'))

关于python - 如何修复 "Unicode strings with encoding declaration are not supported.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57833080/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com