r - XPath在R中的br标签之后提取文本

标签 r xpath

如何提取br之后的文本以下几行中的标签:

<div id='population'>
    The Snow Leopard Survival Strategy (McCarthy <em>et al.</em> 2003, Table
    II) compiled national snow leopard population estimates, updating the work
    of Fox (1994). Many of the estimates are acknowledged to be rough and out
    of date, but the total estimated population is 4,080-6,590, as follows:<br>
    <br>
    Afghanistan: 100-200?<br>
    Bhutan: 100-200?<br>
    China: 2,000-2,500<br>
    India: 200-600<br>
    Kazakhstan: 180-200<br>
    Kyrgyzstan: 150-500<br>
    Mongolia: 500-1,000<br>
    Nepal: 300-500<br>
    Pakistan: 200-420<br>
    Russia: 150-200<br>
    Tajikistan: 180-220<br>
    Uzbekistan: 20-50
</div>

我得到了:
xpathSApply(h, '//div[@id="population"]', xmlValue)

但我现在卡住了...

最佳答案

如果您意识到文本也是一个节点,它会有所帮助。 div 中的所有文本都紧随其后 <br/>可以通过以下方式检索:

//div[@id="population"]/text()[preceding-sibling::br]

从技术上讲,在 <br/> 之间标签意味着:
//div[@id="population"]/text()[preceding-sibling::br and following-sibling::br]

......但我想这不是你现在想要的。

关于r - XPath在R中的br标签之后提取文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11252407/

相关文章:

c++ - C 的 R API 中 R.3.4.4 和 R.3.5.1 的区别

html - 无法在 Scrapy 中使用 XPath 访问 HTML 元素

r - 如何突出 ggplot 上的差异?

r - "If"、 "else"、 "is.na()"在 R 的一个函数中的用法

r - 计算与当前行相关的条件匹配的行

Xpath "ends-with"不起作用

java - 从excel导入数据并在xpath的一部分中使用

java - 无法计算 XPath 中的表达式

java - 使用XPath函数抓取所有匹配的内容

当主题之间的 "time"值不同时,在 R 中 reshape