나는 거미 (아래)를 가지고 있으며, 처음 10 분마다 Cron 작업을 통해 실행할 수 있기를 원합니다. CSV의 해당 필드에 항목을 추가하는 대신 필드를 다시 작성합니다. 어떻게하면 몇 번이나 실행해도 필드 헤더가 상위 그룹에 있고 그 아래의 모든 데이터 만 가질 수 있도록 만들 수 있습니까? 나는 CsvItemExporter 클래스와 주위에 엉망이 있고 include_headers_line = false로 설정하지만 프로젝트 구조에 클래스를 추가 할 경우 모르겠습니다 수처럼Scrapy CSV 출력 중복 필드
import scrapy
class Wotd(scrapy.Item):
word = scrapy.Field()
definition = scrapy.Field()
sentence = scrapy.Field()
translation = scrapy.Field()
class WotdSpider(scrapy.Spider):
name = 'wotd'
allowed_domains = ['www.spanishdict.com/wordoftheday']
start_urls = ['http://www.spanishdict.com/wordoftheday/']
custom_settings = {
#specifies exported fields and their order
'FEED_EXPORT_FIELDS': ['word','definition','sentence','translation']
}
def parse(self, response):
jobs = response.xpath('//div[@class="sd-wotd-text"]')
for job in jobs:
item = Wotd()
item['word'] = job.xpath('.//a[@class="sd-wotd-headword-link"]/text()').extract_first()
item['definition'] = job.xpath('.//div[@class="sd-wotd-translation"]/text()').extract_first()
item['sentence'] = job.xpath('.//div[@class="sd-wotd-example-source"]/text()').extract_first()
item['translation'] = job.xpath('.//div[@class="sd-wotd-example-translation"]/text()').extract_first()
yield item
내가 Scrapy의 문서를 읽고 바로는 것 같습니다.
고마워요, 이것이 제가 찾고있는 것입니다. 헤더를 설정하고 변경 한 다음 매력처럼 작동하도록 변경하지 않고 한 번 실행했습니다. 당신의 도움을 주셔서 감사합니다! – GainesvilleJesus