【发布时间】:2016-02-24 14:01:38
【问题描述】:
我需要解析以下片段:
<span> Lekhwiya v <strong class="winner-strong">Zobahan</strong></span>
或
<span> <strong class="winner-strong">Sepahan</strong> v Al Nasr (UAE)</span>
正确地作为Lekhwiya v Zobahan 和Sepahan v Al' Nasr'(UAE)。
我试图解析为:
team_1 = block.xpath('.//span/text()').extract()[:2]
team_1 = team_1[0].strip() + team_1[1].strip()
team_2 = block.xpath('.//span/strong/text()').extract()[0]
item['match'] = team_2.strip() + ' ' + team_1 if team_1[0] == 'v' else team_1 + ' ' + team_2.strip()
对我来说,这是一个丑陋的解决方案。最好的方法是什么?
【问题讨论】:
标签: python python-2.7 parsing xpath scrapy