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