簡體   English   中英

Scrapy:抓取CSV文件-未獲得任何輸出

[英]Scrapy: Scraping CSV File - not getting any output

我按照以下示例操作: CSVFeedSpider抓取CSV數據,生成了“ item.xml”,但xml文件中沒有任何內容。

有人可以幫忙嗎? 謝謝!

csvspider.py

class MySpider(CSVFeedSpider):
    name = 'csvexample'
    start_urls = ['file:///D:/desktop/example.csv']
    delimiter = ','
    headers = ['Address', 'Website']

    def parse_row(self, response, row):
        log.msg('Hi, this is a row!: %r' % row)
        item = csvItems()
        item['address'] = row['Address']
        item['website'] = row['Website']
        return item

items.py

class csvItems(Item):
    address = Field()
    website = Field()

example.csv

Item,Address,Website
1,"this, address","www.google.com"

用於運行的命令

scrapy crawl csvexample -o item.xml -t xml

如果您自己運行蜘蛛程序,而沒有輸出參數,那么您可能會看到類似於以下內容的錯誤:

2014-05-12 08:08:41+0100 [scrapy] WARNING: ignoring row 1 (length: 3, should be: 2)
2014-05-12 08:08:41+0100 [scrapy] WARNING: ignoring row 2 (length: 3, should be: 2)

要解決此問題,請按如下所示修改Spider代碼中的標題行:

headers = ['Item', 'Address', 'Website']

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM