xpath获取所有文本,而不仅仅是第一个lin

2024-05-14 20:28:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这个html

    <td colspan="2" align="justify" class="inPage">
                <p>
                    2 bedroom + maids +balcony in Tiara Residence - Diamond type
                    <br>1700 sq.ft, furnished with kitchen equipment
                    <br>Sea view/ Atlantis view
                    <br>Selling Price: 4 million
                </p>
    </td>

我的xpath是:

^{pr2}$

结果就是2 bedroom + maids +balcony in Tiara Residence - Diamond type

我需要p标记中的其他文本。在

我在python0.27

中使用scrapy0.20

Tags: inbrviewhtmltypetdaligndiamond
1条回答
网友
1楼 · 发布于 2024-05-14 20:28:23

你可以简单地使用

normalize-space(.//div[@class='section']/table/tr[7]/td/p)

但是这连接了所有文本节点,没有任何换行符。在

normalize-space()与其他需要字符串参数的XPath字符串函数一样,将把输入节点p转换为它的string-value。引用XPath 1.0 specifications

For every type of node, there is a way of determining a string-value for a node of that type. For some types of node, the string-value is part of the node; for other types of node, the string-value is computed from the string-value of descendant nodes

相关问题 更多 >

    热门问题