pumping items out to csv file using python scrapy - issue with how outputted in csv file -
pumping items out to csv file using python scrapy - issue with how outputted in csv file -
having issue want add together output csv file not start below field name placed in next row in sequence opposed placing @ row 2 when populating playermins item in csv file. can please tell me code going wrong?? here is:
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() 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() p_minute in p_minutes: print p_minute yield espnitem(playermins=p_minute)
was able solve issue, after much googling , rtfm: trying utilize itemexporter in scrapy
here working code:
def parse(self, response): hxs = htmlxpathselector(response) player_names = hxs.select('(//table[@class="mod-data"][1]/tbody/tr)') p_name in player_names: l = xpathitemloader(item=espnitem(), selector=p_name ) l.add_xpath('playername', 'td[1]/a/text()') l.add_xpath('playermins', 'td[2]') yield l.load_item() python scrapy
Comments
Post a Comment