如何使用xpath从该输入中仅获取值9?

如何使用xpath从该输入中仅获取值9?,xpath,scrapy,Xpath,Scrapy,我有一些HTML,如下所示 <ol Class="z1"> <li><h3>Number Theory - HCF LCM</h3> <p lang="title">How many pairs of integers (x, y) exist such that the product of x, y and HCF (x, y) = 1080?</p> &l

我有一些HTML,如下所示

<ol Class="z1">
        <li><h3>Number Theory - HCF LCM</h3>
            <p lang="title">How many pairs of integers (x, y) exist such that the product of x, y and HCF (x, y) = 1080?</p>
            <ol class="xyz">
                <li>8</li>
                <li>7</li>
                <li>9</li>
                <li>12</li>
            </ol>
        <ul class="exp"><li class="grey fleft"><span class="qlabs_tooltip_bottom qlabs_tooltip_style_33" style="cursor:pointer;"><span><strong>Correct Answer</strong>Choice (C).</br>9</span> Correct answer</span></li><li class="primary fleft"><a href="hcf-lcm_1.shtml">Explanatory Answer</a></li><li class="grey1 fleft">HCF LCM</li><li class="red1 flrt">Hard</li>
        </ul>
        </li>
</ol>
更新

check = response.xpath('//ol[class="z1"]/li/ul/li/span/strong/text()').extract_first()
if "Correct answer" in check :
    correct_answer = response.xpath('//ol[class="z1"/li/ol/li[3]/text()').extract_first()
如果您不需要,请告诉我:

//ul[@class="exp"]//strong[.="Correct answer"]/following::text()[2]

使用以下xpath获取所需的文本

.//ul[@class="exp"]/li/span/span/text()[not(contains(.,'Choice'))]

感谢您发布解决方案,但是在这4个选项中找不到正确答案,下面在ul中提到了它,其class=exp您只想获得
9
文本,对吗?这是正确答案Yes@NarendrajPutthe返回null,据我所知,您是否试图在strongNo中搜索文本正确答案。这应该定位在“正确答案”下面的
“9”
。nope返回[NULL]这是我测试xpath表达式的实际页面源代码
//ul[@class=“exp”]//br/following::text()[1]
相同的结果?在xpath chrome插件上有效,但在scrapy内部不起作用,到处都没有
//ul[@class="exp"]//strong[.="Correct answer"]/following::text()[2]
.//ul[@class="exp"]/li/span/span/text()[not(contains(.,'Choice'))]