R rvest:找不到函数"xpath_element". [英] R rvest: could not find function "xpath_element"
问题描述
我试图简单地复制rvest::html_nodes()
的示例,但遇到错误:
I am trying to simply replicate the example of rvest::html_nodes()
, yet encounter an error:
library(rvest)
ateam <- read_html("http://www.boxofficemojo.com/movies/?id=ateam.htm")
html_nodes(ateam, "center")
do.call(方法,列表(解析的选择器))中的错误:找不到 函数"xpath_element"
Error in do.call(method, list(parsed_selector)) : could not find function "xpath_element"
如果加载诸如httr
,xml2
,selectr
之类的程序包,也会发生同样的情况.我似乎也有这些软件包的最新版本...
The same happens if I load packages such as httr
, xml2
, selectr
. I seem to have the latest version of these packages too...
诸如xpath_element
,xpath_combinedselector
之类的功能位于哪些程序包中?我如何使它工作?请注意,我在Ubuntu 16.04上运行,因此该代码可能会在其他平台上运行...
In which packages are functions such as xpath_element
, xpath_combinedselector
located? How do I get it to work? Note that I am running on Ubuntu 16.04, so that code might work on other platforms...
推荐答案
我知道这个问题已经很久了,但是我想为可能有类似问题的人发表评论.
I understand this issue is rather old but I wanted to post a comment for those who may have similar issues.
我偶然发现了此错误,无法找到很多帮助.因此,我认为与其针对CSS,不如尝试针对xpath.我不知道最佳做法是什么.
I stumbled upon this same error and was unable to find much help. So, I thought instead of targeting CSS I would try to target the xpath instead. I do not know what the best practice is.
我的原始功能在Ubuntu 16,R 3.4.0上运行良好.但是,它们在Debian 8 R 3.3.3和R 3.4.0上失败.
My original functions worked fine on Ubuntu 16, R 3.4.0. However, they failed on Debian 8 R 3.3.3 and R 3.4.0.
当我将代码修改为以xpath而不是css为目标时,它们开始按预期工作.例如,更改此...
When I modified my code to target xpaths instead of css they began working as expected. For example, changing this...
contents <- link %>%
xml2::read_html() %>%
rvest::html_nodes(css = "pre") %>%
rvest::html_text()
对此...
contents <- link %>%
xml2::read_html() %>%
rvest::html_nodes(xpath = "//pre") %>%
rvest::html_text()
解决了我的问题.
这篇关于R rvest:找不到函数"xpath_element".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!