gpt4 book ai didi

python - 无法使用 scrapy 从 Reddit 嵌入式提要窗口中获取 `href`

转载 作者:太空狗 更新时间:2023-10-30 01:10:55 28 4
gpt4 key购买 nike

我正在尝试从以下链接的 reddit 提要窗口中获取 reddit 帐户名称:

fetch('https://coinmarketcap.com/currencies/ripple/')

现在,我可以使用以下代码成功获取 Twitter 帐户详细信息:

#fetch the tweet account of coin
tweet_account = response.xpath('//a[starts-with(@href, "https://twitter.com")]/@href').extract()
tweet_account = [s for s in tweet_account if s != 'https://twitter.com/CoinMarketCap']
tweet_account = [s for s in tweet_account if len(s) < 60 ]
print(tweet_account)

但是,我无法使用类似的方法获得 reddit 帐户??

reddit_account = response.xpath('//a[starts-with(@href, "https://www.reddit.com")]/@href').extract()
reddit_account = [s for s in reddit_account if s != 'https://www.reddit.com/r/CoinMarketCap'']
reddit_account = [s for s in reddit_account if len(s) < 60 ]
print(reddit_account)

即使我尝试使用简单的 xpath 直接获取数据,但它不起作用:

response.xpath('//*[@id="reddit"]/div/div[1]/h4/a[2]/@href')

输出为:

response.xpath('//*[@id="reddit"]').extract() 

表演

<b>['<div id="reddit" class="col-sm-6 text-left">\n</div>']</b>

但是这个div标签里面还有很多标签??为什么我无法获得这些标签??

不幸的是,Scrapy 无法找到这个 div 中的内容。这个 reddit 提要甚至没有 iframe。我应该调用任何单独的 URL 吗??

编辑<\b>:

我确实在 shell 中显示(响应)。它有 twitter 数据但没有 reddit ??为什么会这样?

最佳答案

所有数据都不会在网站中显示的页面源中。如果您使用的是 google chrome 浏览器,请按 ctrl+u 查看页面源,然后按 ctrl+f 搜索您想要的数据。如果它不在页面源中,您可能必须发送一些其他请求才能获取数据。

关于python - 无法使用 scrapy 从 Reddit 嵌入式提要窗口中获取 `href`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55332452/

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