无法使用scrapy

时间:2019-03-25 06:44:07

标签: python scrapy

我正在尝试通过以下链接从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 Feed甚至没有iframe。我应该打电话给其他URL吗?

编辑<\ b>:

我确实在shell中显示了(响应)。并且它具有Twitter数据,但没有reddit?为什么应该这样?

1 个答案:

答案 0 :(得分:4)

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