【发布时间】:2015-07-26 00:22:23
【问题描述】:
我正在使用 scrapy 尝试在嵌套类中检索 url 数据。我已经尝试按照教程和类似的问题进行操作,但我在看似简单的任务中做得很短。
我要抓取的页面是这个: http://www.leasingcar.dk/privatleasing
对于页面上的每一辆车,我都想获取指向“data-nice_url”文本的 xpath。因此,第一个结果应该是“/privatleasing/Citro%c3%abn-Berlingo/eHDi-90-Seduction-E6G”。但我每次都得到一个空数据集。我试过改变 xpath 没有任何外观。
我的代码如下所示:
from scrapy.spiders import Spider
from stack.items import StackItem
from scrapy.selector import Selector
class Spider(Spider):
name = "leasingcar"
allowed_domains = ["http://www.leasingcar.dk"]
start_urls = ["http://www.leasingcar.dk/privatleasing",]
def parse(self, response):
hxs = Selector(response)
print hxs.xpath('//div[@class="data-nice_url"]/text()').extract()
提前致谢
【问题讨论】:
标签: python html xpath web-scraping scrapy