Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

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?

like image 327
Mohammad Avatar asked Apr 17 '15 23:04

Mohammad


1 Answers

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

like image 150
LyzandeR Avatar answered Sep 28 '22 08:09

LyzandeR