html_attrs_dfr: Convert collection of html nodes into data frame

View source: R/html.R

html_attrs_dfrR Documentation

Convert collection of html nodes into data frame

Description

Convert collection of html nodes into data frame

Usage

html_attrs_dfr(
  x,
  attrs = NULL,
  trim = FALSE,
  defaults = NA_character_,
  add_text = TRUE
)

Arguments

x

xml_nodeset object, containing text and attributes of interest

attrs

character vector of attribute names. If missing, all attributes will be used

trim

if TRUE, will trim leading and trailing spaces

defaults

character vector of default values to be passed to rvest::html_attr(). Recycled to match length of attrs

add_text

if TRUE, node content will be added as .text column (using rvest::html_text)

Value

data frame with one row per xml node, consisting of an html_text column with text and additional columns with attributes

Examples


library(polite)
library(rvest)
bow("https://en.wikipedia.org/wiki/List_of_cognitive_biases") %>%
  scrape() %>%
  html_nodes("tr td:nth-child(1) a") %>%
  html_attrs_dfr()
  

polite documentation built on July 9, 2023, 5:21 p.m.