gpt4 book ai didi

python - 从亚马逊网站获取 href 链接时出现问题。 xpath 找到的 href 链接比预期多得多。

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

我正在尝试从下面的亚马逊网站收集每个视频的所有网址。

https://www.amazon.com/video-Prime/s?ie=UTF8&page=1&rh=n%3A2858778011%2Ck%3Avideo

我正在使用 scrapy shell 交互式测试我的代码。我像下面一样启动了 scrapy shell。我

scrapy shell 'https://www.amazon.com/s/ref=nb_sb_noss_1?url=search-alias%3Dinstant-video&field-keywords=video&rh=n%3A2858778011%2Ck%3Avideo'

我的响应状态是200。然后在scrapy shell中,我尝试使用xpath选择器提取所有视频网址,如下所示:

response.xpath("//ul[contains(@id, 's-results-list-atf')]/li//a/@href").extract()   

我得到的 href 链接比预期的要多。当我检查网页 html 时,这没有意义。该页面上有 10 个视频,每个视频只有一个 href 链接。我不明白为什么会发生这种情况。如果有人可以提供帮助,我将不胜感激。预先非常感谢。

最佳答案

尝试下面的 XPath 仅匹配所需的链接

//ul[@id="s-results-list-atf"]//a[h2]/@href

关于python - 从亚马逊网站获取 href 链接时出现问题。 xpath 找到的 href 链接比预期多得多。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48478337/

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