【问题标题】:Using rvest functions on a dataframe column在数据框列上使用 rvest 函数
【发布时间】:2021-02-16 14:43:49
【问题描述】:

我有一个大数据框,称为“输出”,其中一列是 html,称为“原始”。

我正在尝试创建一个新列 style_col,它采用具有它的任何元素的样式属性。这是我的尝试:

style_col <- output %>% 
  mutate(style = read_html(raw) 
         %>% html_node('[style]') 
         %>% html_attr('style')) 

从 HTML 中提取样式的部分适用于单个 HTML,但我似乎无法获得正确的语法以在数据帧上进行操作。这样做的正确方法是什么?谢谢

【问题讨论】:

    标签: html r web-scraping rvest


    【解决方案1】:
    style_col <- output %>% 
      rowwise() %>% # I added this part
      # changed the formatting only here
      mutate(
        style = read_html(raw) %>%
          html_node('[style]') %>%
          html_attr('style')
        ) 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-09
      • 2019-10-19
      • 1970-01-01
      • 1970-01-01
      • 2020-04-21
      相关资源
      最近更新 更多