【发布时间】:2018-02-11 15:33:00
【问题描述】:
我正在尝试抓取使用 angular.js 的网页。我的理解是R中唯一的选择是先使用RSelenium加载页面,然后解析内容。但是,我发现rvest 比 RSelenium 更直观地解析内容,因此我想尽可能少地使用 RSelenium,然后尽快切换到rvest。
到目前为止,我已经意识到我可能至少需要使用 RSelenium 来连接并使用 htmlTreeParse 下载 html 代码。假设这是我的输出的一部分:
structure(list(name = "div", attributes = structure(c("im_dialog_date",
"dialogMessage.dateText"), .Names = c("class", "ng-bind")), children = structure(list(
text = structure(list(name = "text", attributes = NULL, children = NULL,
namespace = NULL, namespaceDefinitions = NULL, value = "6:52 PM"), .Names = c("name",
"attributes", "children", "namespace", "namespaceDefinitions",
"value"), class = c("XMLTextNode", "XMLNode", "RXMLAbstractNode",
"XMLAbstractNode", "oldClass"))), .Names = "text"), namespace = NULL,
namespaceDefinitions = NULL), .Names = c("name", "attributes",
"children", "namespace", "namespaceDefinitions"), class = c("XMLNode",
"RXMLAbstractNode", "XMLAbstractNode", "oldClass"))
如何将其传递给rvest::read_html()?
【问题讨论】:
-
我怀疑你需要绕过
read_html,而不是喂它。read_html的目的是下载数据,以便后续函数(例如,html_nodes)可以对其进行处理。不幸的是,对read_html的输出的简要检查表明它并非微不足道,因为它不包含实际数据,只是指针。这可能是很多事情,但逆向工程要困难得多。也许您应该考虑直接使用xml2而不是通过rvest?
标签: r web-scraping html-parsing rvest rselenium