Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
rvest r数据刮取返回空表_R_Web Scraping_Rvest - Fatal编程技术网

rvest r数据刮取返回空表

rvest r数据刮取返回空表,r,web-scraping,rvest,R,Web Scraping,Rvest,编程新手,尝试从下面的站点删除数据。当我运行下面的代码时,它返回一个空的数据集或表。任何帮助或替代方案都将不胜感激 url <- "https://fasttrack.grv.org.au/Dog/Form?id=2003010003" tab <- url %>% read_html %>% html_node("dogruns_wrapper") %>% html_text() View(tab) url% html_节点(“dogr

编程新手,尝试从下面的站点删除数据。当我运行下面的代码时,它返回一个空的数据集或表。任何帮助或替代方案都将不胜感激

url <- "https://fasttrack.grv.org.au/Dog/Form?id=2003010003" 
tab <- url %>% read_html %>%  
  html_node("dogruns_wrapper") %>%  
  html_text()    
View(tab)
url%
html_节点(“dogruns_包装”)%>%
html_text()
视图(选项卡)

已尝试使用xpath和相同的结果,并且html_table()而不是text返回一个错误,即应用于类“xml_missing”的对象的“html_table”没有适用的方法

正如Mislav所说,该表是用JavaScript生成的,因此最好的选择是
RSelenium

此外,如果您想获取该表,如果使用
html\u table()
,则可以用更少的代码获取该表

我的尝试:

# Load packages
library(rvest) #Loading the rvest package
library(magrittr) # for the '%>%' pipe symbols
library(RSelenium) # to get the loaded html of the webpage

# starting local RSelenium (this is the only way to start RSelenium that is working for me atm)
selCommand <- wdman::selenium(jvmargs = c("-Dwebdriver.chrome.verboseLogging=true"), retcommand = TRUE)
shell(selCommand, wait = FALSE, minimized = TRUE)
remDr <- remoteDriver(port = 4567L, browserName = "chrome")
remDr$open()

# define url
url <- "https://fasttrack.grv.org.au/Dog/Form?id=2003010003"

# go to website
remDr$navigate(url)

# as it's being loaded with JavaScript and it has a slow load, add a sleep here
Sys.sleep(10) # increase as needed

# get the html object of the webpage
html_obj <- remDr$getPageSource(header = TRUE)[[1]] %>% read_html()

# read the table in the html_obj
tab <- html_obj %>%  html_table() %>% .[[1]]
#加载包
库(rvest)#加载rvest包
库(magrittr)#用于“>%”管道符号
库(RSelenium)#获取网页加载的html
#启动本地RSelenium(这是启动为我工作的RSelenium的唯一方法)

selCommand我认为不能使用rvest完成,因为表是通过JavaScript生成的。您应该尝试使用RSelenium/splashr或其他JavaScript呈现服务。谢谢您。我会调查的。非常好的尤奈!!!这个表是用Javascript动态生成的吗?我测试了一些浮现在脑海中的想法,但我无法让它工作。我甚至无法让我的代码识别该URL上的一个表,但显然有一个表。我所能想到的就是Javascript从服务器动态地提取数据,并在页面加载时创建表,但我不确定。更多关于这方面的信息将非常好!谢谢哇,谢谢你,乌奈!!在米斯拉夫把我送到正确的方向后,我想弄明白这一点,但你说得很简单,谢谢。绝对已经阅读了t's和c's,这只供个人使用,但感谢您的关注。@ryguy72我想是的。装载要花很多时间,所以这是我的猜测。我自己还没有检查源代码,所以我不能确定。关于这个问题/解决方案,您有什么具体问题?@J.Doe不客气!如果您对解决方案有任何不了解的地方,请告诉我!如果它对您有效,请不要忘记将我的解决方案标记为答案:)@UnaiSanchez在输入第二行代码时,在第二行代码上出现此错误;shell错误(selCommand,wait=FALSE,minimized=TRUE):找不到函数“shell”,似乎在创建远程驱动程序时遇到问题。这是因为我用的是Mac电脑吗?我可以通过Splash和Docker运行一个远程生态系统,但还没有找到任何代码来复制你通过Splash在RSelenium中所做的事情。