我正在嘗試洗掉幾個網頁,特別是頁面中的一些表格。但問題是表格的位置隨每一頁而變化。這是我的代碼。
url <- paste0("https://en.wikipedia.org/wiki/2011–12_Welsh_Premier_League")
webpage <- read_html(url)
j<-webpage%>% html_node(xpath='//*[@id="mw-content-text"]/div[1]/table') %>%html_table(fill=T)
這段代碼運行良好,但我也想放棄其他季節。餐桌位置隨季節變化。我的問題是我發現我要廢棄的表類被命名為“wikitable plainrowheaders”,如下所示。我想知道如何用表類名報廢。如何在維基百科頁面中廢棄所有表類名為“wikitable plainrowheaders”的表?
<table class="wikitable plainrowheaders" style="text-align:center;font-size:100%;">
提前謝謝了。
uj5u.com熱心網友回復:
既然知道表類名,就改一下對應的xpath。
library(rvest)
url <- paste0("https://en.wikipedia.org/wiki/2011–12_Welsh_Premier_League")
webpage <- read_html(url)
j <- webpage %>%
html_nodes(xpath="//table[@class='wikitable plainrowheaders']") %>%
html_table(fill=T)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/483246.html
