无法使用scrapy通过此代码提取任何数据

时间:2017-09-27 13:14:04

标签: python web-scraping scrapy

我正在学习如何使用scrapy,但我在运行第一只蜘蛛时遇到了麻烦。这是我的代码,但它不提取任何数据!你能帮帮我:)

    import scrapy

    class Housin(scrapy.Spider):
        name ='housin'
        star_urls = ['http://www.metrocuadrado.com/apartamento/venta/bogota/usado/']

        def parse (self,response):
            for href in response.css('a.data-details-id::attr(href)'):
                yield response.follow(href, self.parse_livi)

        def parse_livi(self,response):
            yield {
                'latitude': response.xpath('//input[@id="latitude"]/@value').extract_first(),
                'longitud': response.xpath('//input[@id="longitude"]/@value').extract_first(),
                'price': response.xpath('//dd[@class="important"]/text()').extract_first(),
                'Barrio_com': response.xpath('.//dl/dt[h3/text()="Nombre común del barrio "]/following-sibling::dd[1]/h4/text()').extract_first(),
                'Barrio_cat': response.xpath('.//dl/dt[h3/text()="Nombre del barrio catastral"]/following-sibling::dd[1]/h4/text()').extract_first(),
                'Estrato': response.xpath('.//dl/dt[h3/text()="Estrato"]/following-sibling::dd[1]/h4/text()').extract_first(),
                'id': response.xpath('//input[@id="propertyId"]/@value').extract_first()
                }

1 个答案:

答案 0 :(得分:1)

您的问题是您的刮刀根本没有启动。

下面
star_urls = ['http://www.metrocuadrado.com/apartamento/venta/bogota/usado/']

应该是

start_urls = ['http://www.metrocuadrado.com/apartamento/venta/bogota/usado/']

该拼写错误(缺少t)会导致scrapy找不到任何起始网址,因此抓取工作根本无法启动