【问题标题】:R node {xml_nodeset} to xml or htmlR 节点 {xml_nodeset} 到 xml 或 html
【发布时间】:2018-07-26 18:19:09
【问题描述】:

xml2::read_html/rvest生成的任意假设节点,例如:

require(xml2); require(rvest)
doc = read_html('https://www.w3.org/TR/html4/intro/intro.html')
e = html_node(doc, '.subtoc')

有没有办法将e 转换回html?我能做的最接近的事情是:

xml2::write_html(e, 'e.html')
head(readLines('e.html'))
[1] "<div class=\"subtoc\">"                                               
[2] "<p><strong>Contents</strong></p>"                                     
[3] ""                                                                     
[4] "<ol>"                                                                 
[5] "<li>"                                                                 
[6] "<a class=\"tocxref\" href=\"#h-2.1\">What is the World Wide Web?</a> "

【问题讨论】:

    标签: html r xml-parsing rvest xml2


    【解决方案1】:

    您可以尝试将节点转换为字符,然后重复 read_html 代码。

    newdoc <-read_html(as.character(e))
    
    write_html(newdoc, e.html)
    

    这将创建一个可读的 html 文档。

    【讨论】:

      猜你喜欢
      • 2016-05-08
      • 1970-01-01
      • 1970-01-01
      • 2011-07-30
      • 1970-01-01
      • 2012-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多