【发布时间】:2019-11-08 17:11:56
【问题描述】:
使用rvest,如何选择没有属性的节点?
例如:
<nodes>
<node attribute1="aaaa"></node>
<node attribute1="bbbb"></node>
<node></node> <- FIND THIS
</nodes>
这是一个使用 XPath 的相关 thread,但是当我尝试使用类似于
的rvest
wp %>% html_read(.) %>% html_nodes(xpath = "//node[not(@*)")
wp 是所需的网址,我出错了:
Warning message:
In xpath_search(x$node, x$doc, xpath = xpath, nsMap = ns, num_results = Inf) :
Invalid predicate [1206]
当我可以看到我想要抓取的内容在页面源中没有属性时。
坦率地说,我只是不太了解 Web 开发和 HTML,无法理解如何将此示例推广到 rvest 的文档。任何帮助或资源将不胜感激!
编辑:
在rvest 中实现此目的的正确代码是
wp %>% html_read(.) %>% html_nodes(xpath = "//node[not(@*)]")
【问题讨论】: