将`xml_document/xml_node`对象保存在Tibble中进行变异 [英] Save `xml_document/xml_node` object in a tibble for mutating
本文介绍了将`xml_document/xml_node`对象保存在Tibble中进行变异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要将html页面保存到Tibble,以便以后可以对页面内容使用变异体
我想过将html直接读取到Tibble:
library(tidyverse)
library(rvest)
#does not work
tibble(html=read_html("https://www.accessdata.fda.gov/scripts/cder/daf/index.cfm?event=overview.process&ApplNo=040445"))
#> Error: All columns in a tibble must be vectors.
#> x Column `html` is a `xml_document/xml_node` object.
作为list
作品阅读:
#works
works <- tibble(html=list(read_html("https://www.accessdata.fda.gov/scripts/cder/daf/index.cfm?event=overview.process&ApplNo=040445")))
works
#> # A tibble: 1 x 1
#> html
#> <list>
#> 1 <xml_dcmn>
但是,我不能使用mutate
THEN:
# does not work
works %>%
mutate(table=html_nodes(unlist(page),"#exampleApplSuppl"))
#> Error: Problem with `mutate()` column `table`.
#> i `table = html_nodes(unlist(page), "#examleApplSuppl")`.
由reprex package(v2.0.1)创建于2021-11-02
HTML
因为‘推荐答案’列是list
,所以在list
上循环并在list
library(purrr)
library(dplyr)
works %>%
mutate(table = map(html, ~ html_nodes(.x, "#examleApplSuppl")))
-输出
# A tibble: 1 × 2
html table
<list> <list>
1 <xml_dcmn> <xml_ndst>
这篇关于将`xml_document/xml_node`对象保存在Tibble中进行变异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文