私はスパイダー(下記)を持っていますが、最初に実行するたびに10日ごとにCronジョブを実行したいと考えています。アイテムをCSVの適切なフィールドに追加するのではなく、フィールドを書き換えます。どのように何回実行しても、フィールドヘッダーの1つのグループとその下のすべてのデータのみを持つようにするにはどうしたらよいですか?私はCsvItemExporterクラスで周りの混乱に持っているとinclude_headers_line = Falseに設定されますが、私はプロジェクト構造にそのクラスを追加する場所を確認していないことのように治療用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