LiveHTML | R Documentation |
You construct an LiveHTML object with read_html_live()
and then interact,
like you're a human, using the methods described below. When debugging a
scraping script it is particularly useful to use $view()
, which will open
a live preview of the site, and you can actually see each of the operations
performed on the real site.
rvest provides relatively simple methods for scrolling, typing, and clicking. For richer interaction, you probably want to use a package that exposes a more powerful user interface, like selendir.
session
Underlying chromote session object. For expert use only.
new()
initialize the object
LiveHTML$new(url)
url
URL to page.
print()
Called when print()
ed
LiveHTML$print(...)
...
Ignored
view()
Display a live view of the site
LiveHTML$view()
html_elements()
Extract HTML elements from the current page.
LiveHTML$html_elements(css, xpath)
css, xpath
CSS selector or xpath expression.
click()
Simulate a click on an HTML element.
LiveHTML$click(css, n_clicks = 1)
css
CSS selector or xpath expression.
n_clicks
Number of clicks
get_scroll_position()
Get the current scroll position.
LiveHTML$get_scroll_position()
scroll_into_view()
Scroll selected element into view.
LiveHTML$scroll_into_view(css)
css
CSS selector or xpath expression.
scroll_to()
Scroll to specified location
LiveHTML$scroll_to(top = 0, left = 0)
top, left
Number of pixels from top/left respectively.
scroll_by()
Scroll by the specified amount
LiveHTML$scroll_by(top = 0, left = 0)
top, left
Number of pixels to scroll up/down and left/right respectively.
type()
Type text in the selected element
LiveHTML$type(css, text)
css
CSS selector or xpath expression.
text
A single string containing the text to type.
press()
Simulate pressing a single key (including special keys).
LiveHTML$press(css, key_code, modifiers = character())
css
CSS selector or xpath expression. Set to NULL
key_code
Name of key. You can see a complete list of known keys at https://pptr.dev/api/puppeteer.keyinput/.
modifiers
A character vector of modifiers. Must be one or more
of "Shift
, "Control"
, "Alt"
, or "Meta"
.
clone()
The objects of this class are cloneable with this method.
LiveHTML$clone(deep = FALSE)
deep
Whether to make a deep clone.
## Not run:
# To retrieve data for this paginated site, we need to repeatedly push
# the "Load More" button
sess <- read_html_live("https://www.bodybuilding.com/exercises/finder")
sess$view()
sess %>% html_elements(".ExResult-row") %>% length()
sess$click(".ExLoadMore-btn")
sess %>% html_elements(".ExResult-row") %>% length()
sess$click(".ExLoadMore-btn")
sess %>% html_elements(".ExResult-row") %>% length()
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.