TL;DR: For web scraping in R, use rvest to parse HTML with CSS selectors or XPath and httr2 to fetch pages with retries and rate limits. rvest alone is fine for one page; once you crawl, fetch with httr2 and parse with rvest, and use read_html_live() when JavaScript builds the page. This guide covers tables, pagination, script-tag data, scraper APIs, and offline tests.
The data you need sits on a web page, and you want it in a tibble without leaving R. Web scraping in R gets you there with two packages and the tidyverse you already know. New to the idea? Start with what web scraping is.
This guide uses Goodreads as its running example: the "Best Books Ever" reader list and the page for George Orwell's 1984. You'll parse a page and a table with rvest, crawl a paginated list politely with httr2, pull data that JavaScript builds, hand blocked pages to a scraper API without changing your parser, test your code offline, and summarize the result.
Quick start
- Install:
install.packages(c("rvest", "httr2")) - Load with
read_html(), select withhtml_elements(), extract withhtml_text2()orhtml_attr() - Use
read_html_live()for pages that JavaScript builds - Use R 4.1 or later for the native
|>pipe




