提问人:hanku8 提问时间:11/9/2023 最后编辑:hanku8 更新时间:11/9/2023 访问量:18
如何使用 scrapy 抓取带有 xpath 或其他方式的 JSON 元素标签的值?
How to use scrapy to scrape the value of a HTML element tag which is JSON with xpath or in another way?
问:
我使用 Scrapy 抓取页面,到目前为止,我在 XPATH 上取得了成功,但我对那个页面有点挣扎。我正在尝试获取dimensionsImageKey的值:
<img id="fullViewImg" class="img-responsive"
onerror="this.onerror = null; this.src = '/prod/Images/noImageAvalBig.jpg';"
dimensionsImageKey="[{"k":"37081793~SID~B342~S0~I1~RW2576~H1932~TH0","w":2576,"h":1932,"sn":"","sid":37081793,"b":342,"in":1,"i":0,"s":0,"ar":1.33,"art":1.35,"tw":96,"th":72},{"k":"37081793~SID~B342~S0~I2~RW2576~H1932~TH0","w":2576,"h":1932,"sn":"","sid":37081793,"b":342,"in":2,"i":1,"s":0,"ar":1.33,"art":1.35,"tw":96,"th":72])">
我得到的最好的是
response.xpath('//*[@dimensionsimagekey]/@dimensionsimagekey').getall()
它只返回'[{
似乎它只返回两个双引号之间的内容。有没有办法用 Scrapy 和 Xpath 实现这一目标?
答: 暂无答案
评论
dimensionsImageKey
dimensionsImageKey="[{"