rvest:如何在Rstudio中可视化html会话网页?

Moh*_*mad 6 r

我有以下代码:

library(rvest)
s <- html_session("http://had.co.nz")
s %>% jump_to("thesis/")
s %>% follow_link("vita")
Run Code Online (Sandbox Code Playgroud)

现在我想确保导航到正确的网页,如何在Rstudio中可视化网页?

Lyz*_*deR 5

我提供了两种方法,因为我没有得到您感兴趣的方法:

library(rvest)
s <- html_session("http://had.co.nz")
t <- s %>% jump_to("thesis/")
v <- s %>% follow_link("vita")
Run Code Online (Sandbox Code Playgroud)

对于上述任何内容,t或者v您可以使用以下内容查看html代码,看看是否正确:

html(t$url)
html(v$url)
Run Code Online (Sandbox Code Playgroud)

或者在@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))
Run Code Online (Sandbox Code Playgroud)

或根据@MrFLick的评论使用跨平台选项:

browseURL(t$url)
browseURL(v$url)
Run Code Online (Sandbox Code Playgroud)

实际查看网页本身。

(如果您要这样,我认为您不能将Rstudio的查看器用于非本地Web内容)。