【发布时间】:2018-06-12 16:33:09
【问题描述】:
我正在从一个看起来像这样的网站抓取数据:
<div class="content">
<blockquote>
<div>
Do not select this.
</div>
How do I select only this…
<br />
and this…
<br />
and this in a single node?
</blockquote>
</div>
假设像这样的 sn-p 在单个页面上出现 20 次,我想获取 <blockquote> 中的所有文本,但忽略子节点中的所有内容,例如内部 div。
因此我使用:
html %>%
html_nodes(xpath = "//*[@class='content']/blockquote/text()[normalize-space()]")
但是,这会将 How do I select only this…、and this…、and this in a single node? 分隔为 xml_nodeset 结构中的各个元素。
我应该怎么做才能基本上将所有这些文本节点连接成一个并返回相同的 20 个元素(或者如果我只有这个示例,则返回一个)?
【问题讨论】:
标签: r xpath web-scraping rvest