我正在尝试通过以下链接从reddit feed窗口中获取reddit帐户名称:
fetch('https://coinmarketcap.com/currencies/ripple/')
Run Code Online (Sandbox Code Playgroud)
现在,在这里,我可以使用以下代码成功获取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)
Run Code Online (Sandbox Code Playgroud)
但是,我无法使用类似的方法来获得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)
Run Code Online (Sandbox Code Playgroud)
甚至我都尝试过使用简单的xpath直接获取,但是它不起作用:
response.xpath('//*[@id="reddit"]/div/div[1]/h4/a[2]/@href')
Run Code Online (Sandbox Code Playgroud)
输出为:
response.xpath('//*[@id="reddit"]').extract()
Run Code Online (Sandbox Code Playgroud)
表演
<b>['<div id="reddit" class="col-sm-6 text-left">\n</div>']</b>
Run Code Online (Sandbox Code Playgroud)
但是这个div标签中还有更多标签吗?为什么我无法获得那些标签?
不幸的是,Scrapy无法找到此div内部的内容。此Reddit Feed甚至没有iframe。我应该打电话给其他URL吗?
编辑<\ b>:
我确实在shell中显示了(响应)。并且它具有Twitter数据,但没有reddit?为什么会这样?
所有数据都不会出现在网站中显示的页面源中。如果您使用的是 google chrome 浏览器,请按 ctrl+u 查看页面来源,然后按 ctrl+f 搜索您想要的数据。如果它不在页面源中,您可能需要发送一些其他请求来获取数据。