网页搜集-xPath问题

时间:2018-11-20 17:02:26

标签: xpath web-scraping

我需要从以下HTML代码中提取文本120

<section class="details">
    <h2>Détails du bien</h2>

        <table>
            ....
            <tr>
                <td>Surface habitable (m²)</td>
                <td class="right" title="120">120 </td>
            </tr>
            ...
        </table>
</section>

我使用了这个xpath,但是它返回了一个空列表:

//td[contains(text(),"Surface")]/td[@class="right"]/text()

我在做什么错了?

1 个答案:

答案 0 :(得分:0)

尝试使用xPath axes

//td[contains(text(),"Surface")]/following-sibling::td[@class="right"]/text()

这应该可以解决您的问题。