Beispiel #1
0
	def parse(self, response):
		#inspect_response(response, self)
		round = ItemLoader(item = ResultsItem(), response=response)
		round.add_xpath('home_team', '//td[@class="cThree"]', re='>.*<')
		round.add_xpath('away_team', '//td[@class="cFive"]', re='>.*<')
		round.add_xpath('home_score', '//td[@class="cFour"]/text()')
		round.add_xpath('away_score', '//td[@class="cFour"]/text()')
		round.add_xpath('date', '//td[@class="cOne first"]/text()')
		round.add_xpath('replay', '//td[@class="cTwo"]')
		round.add_xpath('match_id', '//td[@class="last"]/a/@rel')
		round = round.load_item()
		
		match_count = len(round.values()[0]) #number of matches in round
			
		for i in range(match_count):
			match = {} #create new item for each match
			for key, value in round.items():
				match[key] = value[i]
				match['round_id'] = response.meta['round_id']
			yield match 
    def parse(self, response):
        inspect_response(response, self)
        round = ItemLoader(item=ResultsItem(), response=response)
        round.add_xpath("home_team", '//td[@class="cThree"]', re=">.*<")
        round.add_xpath("away_team", '//td[@class="cFive"]', re=">.*<")
        round.add_xpath("home_score", '//td[@class="cFour"]/text()')
        round.add_xpath("away_score", '//td[@class="cFour"]/text()')
        round.add_xpath("date", '//td[@class="cOne first"]/text()')
        round.add_xpath("replay", '//td[@class="cTwo"]')
        round.add_xpath("match_id", '//td[@class="last"]/a/@rel')
        round = round.load_item()
        print round

        match_count = len(round.values()[0])

        for i in range(match_count):
            if round["home_score"][i] == "NaN":  # changed this to pick up missing scorelines
                match = {}  # create new item for each match
                for key, value in round.items():
                    match[key] = value[i]
                    match["round_id"] = response.meta["round_id"]
                yield match