How to scrap with table class name with R?


I am tryng to scrap several web pages, particulaty some tables in the pages.
But the problem is the places of tables change with respect to each page.
Here is my code.

url <- paste0("")
webpage <- read_html(url)
j<-webpage%>% html_node(xpath='//*[@id="mw-content-text"]/div[1]/table') %>%html_table(fill=T)

This code works fine, but I want to scrap the other seaons, too. The place of table changes in every season.
My question is I found that the table class that I want to scrap is named as "wikitable plainrowheaders", as below. I would like to know how to scrap with table class name.
How to scrap all tables with table class named as "wikitable plainrowheaders" in a wikipedia page?

<table class="wikitable plainrowheaders" style="text-align:center;font-size:100%;">

Many thanks in advance.


Since you know the table class name, just change the corresponding xpath.


url <- paste0("")

webpage <- read_html(url)

j <- webpage %>%
  html_nodes(xpath="//table[@class='wikitable plainrowheaders']") %>%

Answered By – bdedu

Answer Checked By – David Goodson (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.