Я не могу визуализировать результаты этого кода с помощью Scrapy:
import scrapy
class TestSpider(scrapy.Spider):
name = 'test'
start_urls = ['https://www.amazon.com/dp/B07Q6H83VY']
def parse(self, response):
for row in response.css('div.review'):
item = {}
item['author'] = row.css('span.a-profile-name::text').extract_first()
rating = row.css('i.review-rating > span::text').extract_first().strip().split(' ')[0]
item['rating'] = int(float(rating.strip().replace(',', '.')))
item['title'] = row.css('span.review-title > span::text').extract_first()
created_date = row.css('span.review-date::text').extract_first().strip()
item['created_date'] = created_date
review_content = row.css('div.reviewText ::text').extract()
review_content = [rc.strip() for rc in review_content if rc.strip()]
item['content'] = ', '.join(review_content)
yield item
Затем
import scrapy
from scrapy.crawler import CrawlerProcess
process = CrawlerProcess({
'USER_AGENT': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)'
})
process.crawl(TestSpider)
process.start()
Я использую блокнот Jupyter. Пример вывода должен быть:
{
"author": "Jhona Diaz",
"rating": 4,
"title": "Recomendable solo si eres fan ya que si está algo caro",
"created_date": "Reviewed in Mexico on November 23, 2019",
"content": "Buena calidad y pues muy completo"
},
{
"author": "MANUEL MENDOZA OLVERA",
"rating": 5,
"title": "Perfecto Estado",
"created_date": "Reviewed in Mexico on September 28, 2019",
"content": "excelente, la edición es de caja metálica y llegó intacta"
},
Не могли бы вы рассказать мне, как получить эти результаты?