scrapy 用Python解码的JSON [复制]

vwoqyblh  于 5个月前  发布在  Python
关注(0)|答案(1)|浏览(78)

此问题在此处已有答案

I'm getting an IndentationError (or a TabError). How do I fix it?(6个回答)
4年前关闭。
(Scrapy)我需要帮助下一个代码:

def parse_item(self, response):
        ml_item = MercadoItem()
        #info de producto
        ml_item['nombre'] = response.xpath('//h1[@class="title"]/text()').extract()
        ml_item['web'] = response.xpath('/html/body/div[1]/div/div/div[1]/main/div/div[1]/div[2]/div[1]/div/div[4]/a/@href').extract()
        script_data = response.xpath('string(/html/head/script[3]/text()').extract()
        decoded_data = json.loads(script_data)
        ml_item['datos'] = decoded_data["telephone"]
        ml_item['direccion'] = response.xpath('/html/body/div[1]/div/div/div[1]/main/div/div[1]/div[2]/div[1]/div/span[2]/text()').extract()
        self.item_count += 1
        if self.item_count > 5:
            raise CloseSpider('item_exceeded')
        yield ml_item

字符串
我只使用解码的JSON获取电话号码,但控制台返回错误script_data包含脚本
文件“/mercadolibre-scrapy-master/mercado/spiders/spiderq.py“,第88行ml_item 'direccion'] = response.xpath('/html/body/div[1]/div/div [1]/main/div/div [1]/div[2]/div[1]/div/span[2]/text(').extract()

^ IndentationError: unexpected indent


脚本是:

{"@context":"http://schema.org","@type":"LocalBusiness","name":"Clínica Dental Castellana 23","description":".TU CLÍNICA DENTAL DE REFERENCIA EN MADRID","telephone":"+34912298837","address":{"@type":"PostalAddress","streetAddress":"Castellana 23","addressLocality":"MADRID","addressRegion":"Madrid","postalCode":"28003"}}

z5btuh9x

z5btuh9x1#

检查错误报告的行,用于对齐该行的缩进与用于前一行的缩进不同,例如,您可能在前面有4个空格,后面有1个制表符,它们可能看起来相同,但对于Python解释器来说它们是不同的。

相关问题