This set of functions allows you to simulate a user interacting with a website, using forms and navigating from page to page.
Create a session with html_session(url)
Navigate to a specified url with jump_to()
, or follow a link on the
page with follow_link()
.
Submit an html_form with session_submit()
.
View the history with session_history()
and navigate back and forward
with back()
and forward()
.
Extract page contents with html_element()
and html_elements()
, or get the
complete HTML document with read_html()
.
Inspect the HTTP response with httr::cookies()
, httr::headers()
,
and httr::status_code()
.
html_session(url, ...) is.session(x) jump_to(x, url, ...) follow_link(x, i, css, xpath, ...) back(x) forward(x) session_history(x) session_submit(x, form, submit = NULL, ...)
url | A URL, either relative or absolute, to navigate to. |
---|---|
... | Any additional httr config to use throughout the session. |
x | A session. |
i | A integer to select the ith link or a string to match the first link containing that text (case sensitive). |
css | Elements to select. Supply one of |
xpath | Elements to select. Supply one of |
form | An html_form to submit |
submit | Which button should be used?
|
s <- html_session("http://hadley.nz") s %>% jump_to("hadley-wickham.jpg") %>% jump_to("/") %>% session_history()#> http://hadley.nz #> http://hadley.nz/hadley-wickham.jpg #> - http://hadley.nz/s %>% jump_to("hadley-wickham.jpg") %>% back() %>% session_history()#> - http://hadley.nz #> http://hadley.nz#>#> {xml_nodeset (61)} #> [1] <p class="d-inline"><a style="color: #ffffff;font-size: .9em;" href="/bl ... #> [2] <p class="d-inline"><a href="/black-lives-matter"> <button class="pt-1 p ... #> [3] <p class="d-inline pl-0 pr-3 text-center"><a class="text-white" href="/b ... #> [4] <p>The premier IDE for R</p> #> [5] <p>RStudio anywhere using a web browser</p> #> [6] <p>Put Shiny applications online</p> #> [7] <p>Shiny, R Markdown, Tidyverse and more</p> #> [8] <p>Do, share, teach and learn data science</p> #> [9] <p>An easy way to access R packages</p> #> [10] <p>Let us host your Shiny applications</p> #> [11] <p>The premier software bundle for data science teams</p> #> [12] <p>RStudio for the Enterprise</p> #> [13] <p>Connect data scientists with decision makers</p> #> [14] <p>Control and distribute packages</p> #> [15] <p>RStudio</p> #> [16] <p>RStudio Server</p> #> [17] <p>Shiny Server</p> #> [18] <p>R Packages</p> #> [19] <p>RStudio Cloud</p> #> [20] <p>RStudio Public Package Manager</p> #> ...# }