html_form | R Documentation |
Use html_form()
to extract a form, set values with html_form_set()
,
and submit it with html_form_submit()
.
html_form(x, base_url = NULL)
html_form_set(form, ...)
html_form_submit(form, submit = NULL)
x |
A document (from |
base_url |
Base url of underlying HTML document. The default, |
form |
A form |
... |
< Provide a character vector to set multiple checkboxes in a set or select multiple values from a multi-select. |
submit |
Which button should be used to submit the form?
|
html_form()
returns as S3 object with class rvest_form
when applied
to a single element. It returns a list of rvest_form
objects when
applied to multiple elements or a document.
html_form_set()
returns an rvest_form
object.
html_form_submit()
submits the form, returning an httr response which
can be parsed with read_html()
.
HTML 4.01 form specification: https://www.w3.org/TR/html401/interact/forms.html
html <- read_html("http://www.google.com")
search <- html_form(html)[[1]]
search <- search %>% html_form_set(q = "My little pony", hl = "fr")
# Or if you have a list of values, use !!!
vals <- list(q = "web scraping", hl = "en")
search <- search %>% html_form_set(!!!vals)
# To submit and get result:
## Not run:
resp <- html_form_submit(search)
read_html(resp)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.