【问题标题】:Printing longer XML nodes in R在 R 中打印更长的 XML 节点
【发布时间】:2021-01-12 11:02:15
【问题描述】:

如何在 R 中打印/显示更长的 XML 节点结果?当我尝试打印它们时,它们只是以 '..." 结尾

library(rvest)

html <- read_html('https://en.wikipedia.org/wiki/COVID-19_pandemic')

# Works fine as the result is short

html_node(html, xpath = '//*[@id="firstHeading"]')

# Does not print the whole result, ends with'...'

long_path <- html_node(html, xpath = '//*[@id="toc"]/ul')
long_path

【问题讨论】:

    标签: r xml rvest


    【解决方案1】:

    你可以这样做:

    cat(as.character(long_path))
    #> <ul>
    #> <li class="toclevel-1 tocsection-1">
    #> <a href="#Epidemiology"><span class="tocnumber">1</span> <span class="toctext">Epidemiology</span></a>
    #> <ul>
    #> <li class="toclevel-2 tocsection-2"><a href="#Background"><span class="tocnumber">1.1</span> <span class="toctext">Background</span></a></li>
    #> <li class="toclevel-2 tocsection-3"><a href="#Cases"><span class="tocnumber">1.2</span> <span class="toctext">Cases</span></a></li>
    #> <li class="toclevel-2 tocsection-4"><a href="#Deaths"><span class="tocnumber">1.3</span> <span class="toctext">Deaths</span></a></li>
    #> </ul>
    #> </li>
    #> etc...
    

    【讨论】:

      猜你喜欢
      • 2018-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多