gpt4 book ai didi

python - 无法使用 scrapy 使用此代码提取任何数据

转载 作者:太空宇宙 更新时间:2023-11-03 14:43:08 24 4
gpt4 key购买 nike

我刚刚学习如何使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com