我有以下代码:
library(rvest)
s <- html_session("http://had.co.nz")
s %>% jump_to("thesis/")
s %>% follow_link("vita")
现在,我要确保已导航到正确的网页,如何在Rstudio中可视化该网页?
最佳答案
我提供了两种方法,因为我没有得到您感兴趣的方法:
library(rvest)
s <- html_session("http://had.co.nz")
t <- s %>% jump_to("thesis/")
v <- s %>% follow_link("vita")
对于上述
t
或v
中的任何一个,您可以使用以下内容查看html代码并查看其是否正确:html(t$url)
html(v$url)
或者在@Mohammad的非常有用的评论之后:
#if you are on windows
shell.exec(t$url)
shell.exec(v$url)
#if you are on mac
system(paste("open", t$url))
system(paste("open", v$url))
或根据@MrFLick的评论使用跨平台选项:
browseURL(t$url)
browseURL(v$url)
实际查看网页本身。
(如果您要这样,我认为您不能将Rstudio的查看器用于非本地Web内容)。
关于rvest : how can I visualize the html session webpage in Rstudio?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29711076/