knitr::opts_chunk$set(
  collapse = TRUE, 
  comment = "#>",
  fig.path = "README-"  
)

rvest

Build Status CRAN_Status_Badge Coverage Status

rvest helps you scrape information from web pages. It is designed to work with magrittr to make it easy to express common web scraping tasks, inspired by libraries like beautiful soup.

library(rvest)
lego_movie <- read_html("http://www.imdb.com/title/tt1490017/")

rating <- lego_movie %>% 
  html_nodes("strong span") %>%
  html_text() %>%
  as.numeric()
rating

cast <- lego_movie %>%
  html_nodes("#titleCast .itemprop span") %>%
  html_text()
cast

poster <- lego_movie %>%
  html_nodes(".poster img") %>%
  html_attr("src")
poster

Overview

The most important functions in rvest are:

To see examples of these function in use, check out the demos.

Installation

Install the release version from CRAN:

install.packages("rvest")

Or the development version from github

# install.packages("devtools")
devtools::install_github("hadley/rvest")

Inspirations



Zyufei/Rstudy documentation built on May 19, 2019, 4:04 p.m.