Печать более длинных узлов XML в R

#r #xml #rvest

#r #xml #rvest

Вопрос:

Как я могу печатать / отображать более длинные результаты узлов XML в R? Когда я пытаюсь их распечатать, они просто заканчиваются ‘…»

 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
  

Ответ №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...