1
私は治療とxpathを使用してデータを抽出したいと思います。これは私のコードです:属性x1,y1
と属性x,y
及びその他(line
)と(image
)最初:xpathの治療からの二重選択
def parse(self, response):
Coords = []
for sel in response.xpath('//*[@id="pitch"]/image[contains(@class,"success")]'):
item = PogbaItem()
item['x'] = sel.xpath('@x').extract()
item['y'] = sel.xpath('@y').extract()
item['x'] = sel.xpath('@x1').extract()
item['y'] = sel.xpath('@y1').extract()
Coords.append(item)
return Coords
問題は、HTMLが2つの異なる要素が含まれていることです。私は取って、最終的なcsvを持ってそれらを一緒に入れようとしているが、私は正しいxpathを見つけることができませんどのように私はそれを解決することはできますか?
更新:HTML
の2つの例:
<image class="pitch-object timer-1-40 success" x="331.172" y="84.678" width="30" height="30" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/sites/fourfourtwo.com/modules/custom/statzone/files/icons/successful_clearance.png"></image>
<line class="pitch-object timer-2-84 success" marker-end="url(#smallblue)" x1="453.076" y1="199.169" x2="509.104" y2="216.676" style="stroke:blue;stroke-width:3"></line>
申し訳ありません、私はhtml要素について間違っていました。私はちょうど私の答えを更新しました – slash89mf
@ slash89mf大丈夫、更新を参照してください。助けてくれますか? – alecxe
これは完璧です!ありがとうございました! – slash89mf