在带有Scrapy的Xpath中使用后续同级

lmyy7pcs  于 2022-11-09  发布在  其他
关注(0)|答案(1)|浏览(105)

我试着从下面的html(https://www.espncricinfo.com/series/indian-premier-league-2022-1298423/punjab-kings-vs-delhi-capitals-64th-match-1304110/full-scorecard)中抓取年份。由于网站的编码方式,我必须首先识别包含单词“Season”的表格单元格,然后获得年份(本例中为2022)。
我原以为这样就可以了,但是没有。没有错误,只是没有结果。我以前没有用过following-sibling方法,所以如果有人能指出我哪里搞砸了,我会很感激的。

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

xmq68pz91#

请尝试:

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

相关问题