【发布时间】:2015-10-27 19:25:51
【问题描述】:
我正在使用scrapy 从python 的网站上抓取信息,而我只是习惯于使用 Xpaths 来查找信息。
我想从此页面返回该艺术家的专辑的所有平均评分列表。 https://rateyourmusic.com/artist/kanye_west
为了找到我使用的专辑的节点//div[@id="disco_type_s"]
我尝试使用div[@class="disco_avg_rating"]/text() 为具有disco_avg_rating 属性的div 搜索孩子
这是我的功能
def parse_dir_contents(self, response):
item = rateyourmusicalbums() *ignore this
for i in response.xpath('//div[@id="disco_type_s"]'):
item['average rating']=i.xpath('div[@class="disco_avg_rating"]/text()').extract()
yield item
我尝试获取此列表的所有内容都会导致问题。通常它更直接,但这次我必须区分专辑和单曲等,所以我遇到了麻烦。
感谢您的帮助,我对网络抓取还很陌生。
【问题讨论】:
标签: python python-2.7 xpath web-scraping scrapy