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

标签 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()
                }

最佳答案

您的问题是您的抓取工具根本无法启动。下面

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/

相关文章:

python - 从 python 3 中的 csv 文件创建字典

python - 如何在 Python 列表中查找元素的索引?

python - 如果列中的值匹配,则合并 Pandas 数据框

python - 我可以抑制 mypy 内联错误吗?

python - 无法使用 xpath 找到 img 元素

r - 捕获验证码图像

php - Parsehub API PHP

r - 使用 Rcurl 抓取数据

python - 如何使用 Scrapy 下载 json Response?

python - Scrapy:从 .py 文件导入项目失败