Mohammad
Mohammad

Reputation: 1098

rvest: how can I visualize the html session webpage in Rstudio?

I have the following code:

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

Now I want to make sure I have navigated to the right webpage, how can I visualize the webpage in Rstudio?

Upvotes: 6

Views: 2903

Answers (1)

LyzandeR
LyzandeR

Reputation: 37879

I provide two ways because I didn't get which one you are interested in:

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

For any of the above t or v you can use the following to view the html code and see if it is correct:

html(t$url)
html(v$url)

OR after @Mohammad's very useful comment:

#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))

Or a cross-platform option as per @MrFLick's comment:

browseURL(t$url)
browseURL(v$url)

To actually view the webpage itself.

(I don't think you can use Rstudio's viewer for non-local web content, if this is what you are asking).

Upvotes: 5

Related Questions