Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a selector to get the second and third element?

I need a way to get the value of the attribute xodd ( tzccftzxt, czofczec, az9faz8p ).

This is the html code:

<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>

and this is my python code:

 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(),
        }

But I only get:

1: tzccftzxt
X: None
2: None

How can I get the second and the third value?

like image 215
xRobot Avatar asked Sep 21 '25 03:09

xRobot


2 Answers

Ok solved:

 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],
        }
like image 187
xRobot Avatar answered Sep 22 '25 18:09

xRobot


Not sure about python but CSS Selecter will be like

td.odds-nowrp[xodd]:nth-child(4)
td.odds-nowrp[xodd]:nth-child(5)
td.odds-nowrp[xodd]:nth-child(6)
like image 45
Irfan Ali Avatar answered Sep 22 '25 17:09

Irfan Ali