2017-09-27 51 views
1

我刚刚学习如何使用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() 
       } 
+0

你是否看了刮登录以检查它是否正在抓取并跟踪URL,以及您的路径声明是否正确......缺少某人为您进行调试 - 您可以轻松地自己本地化它 - 查看日志,为每个项目添加一些打印内容,重新尝试提取等... :) –

回答

1

你的问题是,你的刮刀根本不启动。下面

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

应该

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

那个错误(缺少t)导致scrapy至找不到任何开头的URL,因此刮不启动在所有

+0

非常感谢你!对不起,我是编程新手 –