Я очень новичок в области скрапа и python и могу действительно помочь. У меня есть этот код для работы в командной строке. Я вижу, как он вытаскивает всю нужную информацию, когда она проходит через разные страницы.
Моя проблема в том, что когда я пытаюсь сохранить вывод скрипта в файл, он выходит пустым. Я посмотрел на множество других вопросов здесь, но не могу найти ничего, что поможет.
Вот код
import scrapy
from urlparse import urljoin
class Aberdeenlocations1Spider(scrapy.Spider):
name = "aberdeenlocations2"
start_urls = [
'http://brighthouse.co.uk/store-finder/all-stores',
]
def parse(self, response):
products = response.xpath('//ul/li/a/@href').extract()
for p in products:
url = urljoin(response.url, p)
yield scrapy.Request(url, callback=self.parse_product)
def parse_product(self, response):
for div in response.css('div'):
yield {
title: (response.css('title::text').extract()),
address: (response.css('[itemprop=streetAddress]::text').extract()),
locality: (response.css('[itemprop=addressLocality]::text').extract()),
region: (response.css('[itemprop=addressRegion]::text').extract()),
postcode: (response.css('[itemprop=postalCode]::text').extract()),
telephone: (response.css('[itemprop=telephone]::text').extract()),
script: (response.xpath('//div/script').extract()),
gmaplink: (response.xpath('//div/div/div/p/a/@href').extract_first())
}
Затем я запускаю эту команду на приведенном выше сценарии
scrapy crawl aberdeenlocations2 -o data.json
Что я делаю не так?