1
有一個問題,我想將輸出添加到csv文件,但它不會在字段名稱下面開始,它將放置在下一行而不是在csv文件中填充playerMins項目時將其放置在第2行。有人可以告訴我我的代碼出錯了嗎?那就是:使用python scrapy將項目輸出到csv文件 - 問題如何在csv文件中輸出
class EspnSpider3(BaseSpider):
name = "espn3.org"
allowed_domains = ["espn3.org"]
start_urls = [
"http://scores.espn.go.com/nba/boxscore?gameId=310502004"
]
def parse(self, response):
hxs = HtmlXPathSelector(response)
item = EspnItem()
rows = []
playerName = []
playerMins = []
# player names
p_names = hxs.select('(//table[@class="mod-data"][1]/tbody/tr)//a/text()').extract()
for p_name in p_names:
print p_name
yield EspnItem(playerName=p_name)
# minutes
p_minutes = hxs.select('(//table[@class="mod-data"][1]/tbody/tr)/td[2]').extract()
for p_minute in p_minutes:
print p_minute
yield EspnItem(playerMins=p_minute)
哪裏是你的代碼輸出到CSV? – bernie
scrapy抓取espn3.org --set FEED_URI = items.csv --set FEED_FORMAT = csv –
只是上面的標準c –