gpt4 book ai didi

python - Scrapy 使用错误的编码,从网页向 JSON 添加额外的 html 标签

转载 作者:太空宇宙 更新时间:2023-11-03 15:41:43 25 4
gpt4 key购买 nike

所以我想用Scrapy来获取 Puerto Rico board game data

数据如下所示

  { "data": {
...
"label":"<div class=\"iblock\">\u262f &ge; 75%<\/div>"
...
}

但是,Scrapy中的response.text对象使用不同的编码并添加一些额外的html标签:

<html><head></head><body>
{"data": {
...
"label": "<div class="\&quot;iblock\&quot;">\u262f ≥ 75%&lt;\/div&gt;"
...
}
</div></body></html>

因此,当我尝试将 json 解析为 python 对象时:

responseJSON = json.loads(response.xpath("/html/body/text").extract_first())

我收到以下错误:

ValueError: end is out of bounds

如何让 Scrapy 返回正确编码的响应,而不需要额外的 html 标签?

最佳答案

json.loads(response.text) 

这是json响应,不需要使用xpath

在 scrapy shell 中测试

enter image description here

关于python - Scrapy 使用错误的编码,从网页向 JSON 添加额外的 html 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42055596/

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