html_form {rvest}R Documentation

Parse forms and set values

Description

Use html_form() to extract a form, set values with html_form_set(), and submit it with html_form_submit().

Usage

html_form(x, base_url = NULL)

html_form_set(form, ...)

html_form_submit(form, submit = NULL)

Arguments

x

A document (from read_html()), node set (from html_elements()), node (from html_element()), or session (from session()).

base_url

Base url of underlying HTML document. The default, NULL, uses the url of the HTML document underlying x.

form

A form

...

<dynamic-dots> Name-value pairs giving fields to modify.

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?

  • NULL, the default, uses the first button.

  • A string selects a button by its name.

  • A number selects a button using its relative position.

Value

See Also

HTML 4.01 form specification: https://www.w3.org/TR/html401/interact/forms.html

Examples

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)

[Package rvest version 1.0.4 Index]