简体   繁体   中英

Using Following-sibling in Xpath with Scrapy

I am trying to scrape the year from the html below ( https://www.espncricinfo.com/series/indian-premier-league-2022-1298423/punjab-kings-vs-delhi-capitals-64th-match-1304110/full-scorecard ). Due to the way the site is coded I have to first identify the table cell that contains the word "Season" then get the year (2022 in this example).

I thought this would get it but it doesn't. There are no errors, just no results. I've not used the following-sibling approach before so I'd be grateful if someone could point out where I've messed up.

l.add_xpath(
            'Season',
            "//td[contains(text(),'Season')]/following-sibling::td[1]/a/text()")

html:

<tr class="ds-border-b ds-border-line">
    <td class="ds-min-w-max ds-border-r ds-border-line">
        <span class="ds-text-tight-s ds-font-medium">Season</span>
    </td>
    <td class="ds-min-w-max">
        <span class="ds-inline-flex ds-items-center ds-leading-none">
            <a href="https://www.espncricinfo.com/ci/engine/series/index.html?season2022" class="ds-text-ui-typo ds-underline ds-underline-offset-4 ds-decoration-ui-stroke hover:ds-text-ui-typo-primary hover:ds-decoration-ui-stroke-primary ds-block">
                <span class="ds-text-tight-s ds-font-medium">2022</span>
            </a>
        </span>
    </td>
</tr>

尝试:

//span[contains(text(),"Season")]/../following-sibling::td/span/a/span/text()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM