1
votes

I'm sure a similar question has been answered previously, but I would love to understand why Rvest can't extract data from class = "section wrapper." I'm using R Studio and in short:

anasj_103 = read_html("https://www.hockey-reference.com/boxscores/201810030SJS.html")

ana_table = anasj_103 %>%
    html_node(xpath = '//*[@id="ANA_skaters"]') %>%
    html_table()

adv_ana = anasj_103 %>%
    html_node(xpath = '//*[@id="ANA_adv"]') %>%
    html_table()

Error that comes back: Error in UseMethod("html_table") : no applicable method for 'html_table' applied to an object of class "xml_missing"

The ana_table works fine when using the Xpath but the adv_ana gives an error or returns nothing when using a similar code.I run into this issue with all of the data that is in a div section followed by that class. Since I can't even return basic text in the section wrapper, I'm convinced this is the issue.

Any thoughts or workarounds?

1
It's coming back commented out. Check the existing answers on SO for R , rvest, scraping comments. - QHarr
No. The part you are interested in comes back as html comment so is not accessible with parser as you are trying. - QHarr
Understood - that makes sense. Thanks! - David Tegano
See stackoverflow.com/questions/40616357/… for a couple of examples. There are others on SO. - QHarr
Excellent! Thank you for the assistance here. Still a bit new at this, so this saved me a lot of time. - David Tegano

1 Answers

0
votes

Thanks to QHarr for the assistance. The above question was solved by using:

table = anasjs_103 %>%
    html_nodes(xpath = '//comment()') %>%
    html_text() %>%
    paste(collapse = '') %>%
    read_html() %>%
    html_node('table#ANA_adv') %>%
    html_table()