所以基本上我正在從網(wǎng)絡(luò)上抓取數(shù)據(jù),并且我有一個項(xiàng)目文件導(dǎo)入到我的主蜘蛛文件中?,F(xiàn)在,當(dāng)我抓取數(shù)據(jù)并將其存儲在容器中并將其另存為 csv 時,鏈接列最終總是成為 csv 中的第一列。如何設(shè)置自定義列的位置?
pName = response.css('#search .a-size-medium').css('::text').extract() pPrice = response.css('#search .a-price-whole').css('::text').extract() imgs = response.css('.sbv-product-img , .s-image-fixed-height .s-image').css('::attr(src)').extract() for prod in zip(pName , pPrice , imgs): items['prodName'] = prod[0] items['price'] = prod[1] items['imgLink'] = prod[2] yield items
使用 settings.py
文件或蜘蛛 custom_settings
屬性中的 FEED_EXPORT_FIELDS
設(shè)置。這些列將按照您在設(shè)置值中設(shè)置的順序排列。
例如:
class MySpider(scrapy.Spider): custom_settings = { "FEED_EXPORT_FIELDS": ["prodName", "price", "imgLink"] }
或在settings.py
中:
FEED_EXPORT_FIELDS=["prodName", "price", "imgLink"]