我刚刚学习如何使用 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()
}
最佳答案
您的问题是您的抓取工具根本无法启动。下面
star_urls = ['http://www.metrocuadrado.com/apartamento/venta/bogota/usado/']
应该是
start_urls = ['http://www.metrocuadrado.com/apartamento/venta/bogota/usado/']
该拼写错误(缺少t
)导致scrapy找不到任何起始网址,因此抓取根本无法开始
关于python - 无法使用 scrapy 使用此代码提取任何数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46448861/