Skip to content
Back to skills

Rvest

ASecurity

R rvest package for web scraping. Use for scraping data from web pages.

  • 5 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added June 5, 2026
datajavascriptgojavaapi

Works with

  • api

Security analysis

A100/100

Scanned June 5, 2026

npx -y skills add LeoLin990405/r-analytics-skill --skill rvest --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Rvest?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Rvest
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/leolin990405-rvest/badge)](https://www.skillsdirectory.com/skills/leolin990405-rvest)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: rvest
description: R rvest package for web scraping. Use for scraping data from web pages.
---

# rvest

Easily harvest web pages.

## Basic Scraping

```r
library(rvest)

# Read HTML
page <- read_html("https://example.com")

# From file
page <- read_html("page.html")
```

## Selecting Elements

```r
# CSS selectors
page %>% html_elements("p")
page %>% html_elements(".class")
page %>% html_elements("#id")
page %>% html_elements("div.class")
page %>% html_elements("table tr")

# XPath
page %>% html_elements(xpath = "//div[@class='content']")
```

## Extracting Data

```r
# Text content
page %>%
  html_elements("p") %>%
  html_text()

# Clean text (removes whitespace)
page %>%
  html_elements("p") %>%
  html_text2()

# Attributes
page %>%
  html_elements("a") %>%
  html_attr("href")

# All attributes
page %>%
  html_elements("a") %>%
  html_attrs()
```

## Tables

```r
# Extract tables
tables <- page %>%
  html_elements("table") %>%
  html_table()

# First table
df <- tables[[1]]

# With options
page %>%
  html_element("table") %>%
  html_table(header = TRUE, fill = TRUE)
```

## Forms

```r
# Find form
form <- page %>%
  html_form()[[1]]

# Fill form
form <- form %>%
  html_form_set(
    username = "user",
    password = "pass"
  )

# Submit form
session <- session("https://example.com")
session <- session_submit(session, form)
```

## Sessions

```r
# Start session
session <- session("https://example.com")

# Navigate
session <- session_follow_link(session, "Next")
session <- session_jump_to(session, "https://example.com/page2")

# Go back
session <- session_back(session)

# Get current page
session %>% read_html()
```

## Handling JavaScript

```r
# rvest doesn't execute JavaScript
# For JS-rendered pages, use RSelenium or chromote

# Or find the API endpoint
# Check Network tab in browser DevTools
```

## Example: Scrape Table

```r
library(rvest)
library(dplyr)

url <- "https://en.wikipedia.org/wiki/List_of_countries_by_population"

page <- read_html(url)

df <- page %>%
  html_element("table.wikitable") %>%
  html_table() %>%
  clean_names()
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.