r语言 - 获取 RSelenium 错误:"Failed to decode response from marionette"



我对R相对陌生(对R的刮擦也很陌生),所以如果我在这里忽略了一些明显的东西,请提前道歉!

我一直在尝试通过以下教程学习如何使用RSelenium:https://rawgit.com/petrkeil/Blog/master/2017_08_15_Web_scraping/web_scraping.html#advanced-砷刮除

在终端中运行了以下代码(docker run-d-p 4445:4444 selenium/standalone firefox)后,我尝试运行下面的R代码,只对上面链接的教程进行了轻微修改:

get.tree <- function(genus, species) 
{
# navigate to the page
browser <- remoteDriver(port=4445L)
browser$open(silent = T)
browser$navigate("http://www.bgci.org/global_tree_search.php?sec=globaltreesearch")
browser$refresh()
# create r objects from the web search input and button elements
genusElem <- browser$findElement(using = 'id', value = "genus-field")
specElem <- browser$findElement(using = 'id', value = "species-field")
buttonElem <- browser$fiendElement(using = 'class', value = "btn_ohoDO")
# tell R to fill in the fields
genusElem$sendKeysToElement(list(genus))
specElem$sendKeysToElement(list(species))
# tell R to click the search button
buttonElem$clickElement()
# get output
out <- browser$findElement(using = "css", value = "td.cell_1O3UaG:nth-child(4)") # the country origin
out <- out$getElementText()[[1]] # extract actual text string
out <- strsplit(out, split = "; ")[[1]] # turns into character vector
# close browser
browser$close()
return(out)
}
# Now let's try it:
get.tree("Abies", "alba")

但在做了所有这些之后,我得到了以下错误:

Selenium消息:无法解码来自提线木偶构建信息的响应:版本:"3.6.0",修订:"6fbf3ec767",时间:'2017-09-27T16:15:40.131Z'系统信息:主机:'d260fa60d69b',ip:'172.17.0.2',os.name:'Linux',os.arch:'amd64',os.version:"4.9.49-moby",java.version:"1.8.0_131"驱动程序信息:Driver.version:未知

错误:摘要:未知错误详细信息:未知服务器端错误在处理命令时发生。类别:org.openqa.selenium.WebDriverException进一步详细信息:runerrorDetails方法

有人知道这意味着什么以及我哪里出了问题吗?

非常感谢你的帮助!

只需利用XHR请求来检索联机结果并抛出RSelenium:

library(httr)
library(tidyverse)
get_tree <-  function(genus, species) {
GET(
url = sprintf("https://data.bgci.org/treesearch/genus/%s/species/%s", genus, species), 
add_headers(
Origin = "http://www.bgci.org", 
Referer = "http://www.bgci.org/global_tree_search.php?sec=globaltreesearch"
)
) -> res
stop_for_status(res)
matches <- content(res, flatten=TRUE)$results[[1]]
flatten_df(matches[c("id", "taxon", "family", "author", "source", "problems", "distributionDone", "note", "wcsp")]) %>% 
mutate(geo = list(map_chr(matches$TSGeolinks, "country"))) %>% 
mutate(taxas = list(map_chr(matches$TSTaxas, "checkTaxon")))
}
xdf <- get_tree("Abies", "alba")
xdf
## # A tibble: 1 x 8
##      id      taxon   family author     source distributionDone        geo      taxas
##   <int>      <chr>    <chr>  <chr>      <chr>            <chr>     <list>     <list>
## 1 58373 Abies alba Pinaceae  Mill. WCSP Phans              yes <chr [21]> <chr [45]>
glimpse(xdf)
## Observations: 1
## Variables: 8
## $ id               <int> 58373
## $ taxon            <chr> "Abies alba"
## $ family           <chr> "Pinaceae"
## $ author           <chr> "Mill."
## $ source           <chr> "WCSP Phans"
## $ distributionDone <chr> "yes"
## $ geo              <list> [<"Albania", "Andorra", "Austria", "Bulgaria", "Croatia", "Czech Republic", "Fr...
## $ taxas            <list> [<"Abies abies", "Abies alba f. columnaris", "Abies alba f. compacta", "Abies a...

很可能在某个时候你需要修改get_tree(),但这比使用Selenium、Splash、phantomjs或Headless Chrome作为依赖要好。

相关内容

最新更新