Я пытаюсь запустить мой сгенерированный код для очистки, чтобы очистить страницу в Интернете + сохранить данные в функции item
scrapy, но каждый раз, когда я запускаю код, я получаю:
AttributeError: 'unicode' has no att 'xpath'
Я пытался стереть extract()
после каждого элемента xpath, но это не работает.
Вот код:
class MLSpider(Spider):
name = 'mlivre'
start_urls = ['https://celulares.mercadolivre.com.br/celular']
def parse(self, response):
resposta = response.xpath('//ol').extract()
items = []
for elemento in resposta:
item = TesteItem()
item['Imagem'] = elemento.xpath('//div[contains(@class, "image-content")]/a/@href')
item['Nome'] = elemento.xpath("//div/h2/a/span/text() " )
item['Price'] = elemento.xpath("//div/div/span[@class='price__fraction']/text()" )
item['Desconto'] = elemento.xpath("//div[contains(@class, 'item__discount')]/text()")
item['Vendedor'] = elemento.xpath("//div[contains(@class,'item__brand')]//span/text()")
item['ItensVendidos'] = elemento.xpath(".//div[contains(@class,'item__condition')]/text()")
item['InfoAdicional'] = elemento.xpath(".//p[contains(@class, 'stack-item-info')]/text()")
print(item)
items.append(item)
pass