我正在关注此示例: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
答案 0 :(得分:0)
如果你自己运行蜘蛛而没有输出参数,那么你可能会看到类似于以下的错误:
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)
要解决此问题,请按照以下步骤修改您的代码中的标题行:
headers = ['Item', 'Address', 'Website']