我需要一种方法来获取xodd属性的值(tzccftzxt,czofczec,az9faz8p)。
这是html代码:
<div *ngFor="let Item of Category.Items">
<a *ngIf="Item.isLink" class="animation" (click)="close()">{{Item.Name}}</a>
</div>
这是我的python代码:
<tr class=" deactivate" xeid="A1nOsGN0">
<td class="table-time datet t1523797200-8-1-0-0 ">15/04, 15:00</td>
<td class="name table-participant"><a href="/soccer/italy/serie-a/ac-milan-napoli-A1nOsGN0/">AC Milan - <span class="bold">Napoli</span></a></td>
<td class="center bold table-odds table-score">0:0</td>
<td class="odds-nowrp" xoid="E-2r00txv464x0x6kc61" xodd="tzccftzxt"><a href="" onclick="globals.ch.togle(this , 'E-2r00txv464x0x6kc61');return false;" xparam="odds_text">4.24</a></td>
<td class="result-ok odds-nowrp" xoid="E-2r00txv498x0x0" xodd="czofczec"><a href="" onclick="globals.ch.togle(this , 'E-2r00txv498x0x0');return false;" xparam="odds_text">3.53</a></td>
<td class="odds-nowrp" xoid="E-2r00txv464x0x6kc62" xodd="az9faz8p"><a href="" onclick="globals.ch.togle(this , 'E-2r00txv464x0x6kc62');return false;" xparam="odds_text">1.87</a></td>
<td class="center info-value">5</td>
</tr>
但我只得到:
for partita in response.css('tr.deactivate'):
yield {
'1': partita.css('td.odds-nowrp ::attr(xodd)').extract_first(),
'X': partita.css('td.odds-nowrp:nth-child(1) ::attr(xodd)').extract_first(),
'2': partita.css('td.odds-nowrp:nth-child(2) ::attr(xodd)').extract_first(),
}
如何获得第二个和第三个值?
答案 0 :(得分:2)
好的解决了:
yield {
'PARTITA': partita.css('td.name a::text').extract_first(),
'PUNTEGGIO': partita.css('td.table-score::text').extract_first(),
'1': partita.css('td.odds-nowrp ::attr(xodd)').extract()[0],
'X': partita.css('td.odds-nowrp ::attr(xodd)').extract()[1],
'2': partita.css('td.odds-nowrp ::attr(xodd)').extract()[2],
}
答案 1 :(得分:1)
不确定python但CSS Selecter会像
td.odds-nowrp[xodd]:nth-child(4)
td.odds-nowrp[xodd]:nth-child(5)
td.odds-nowrp[xodd]:nth-child(6)