如何用r刮擦表格名称?
我正在尝试刮擦几个网页,特别是页面中的一些表。
但是问题是表的位置相对于每个页面发生了变化。
这是我的代码。
url <- paste0("https://en.wikipedia.org/wiki/2011%E2%80%9312_Welsh_Premier_League")
webpage <- read_html(url)
j<-webpage%>% html_node(xpath='//*[@id="mw-content-text"]/div[1]/table') %>%html_table(fill=T)
该代码效果很好,但我也想刮擦其他Seaons。桌子的位置在每个季节都会发生变化。
我的问题是,我发现我想刮擦的表班被称为“可鲁特的plainrowheaders”,如下所示。我想知道如何用表格名称刮擦。 如何在Wikipedia页面中使用名为“ Wikiable Plainrowheaders”的表类刮擦所有表?
<table class="wikitable plainrowheaders" style="text-align:center;font-size:100%;">
I am tryng to scrape 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("https://en.wikipedia.org/wiki/2011%E2%80%9312_Welsh_Premier_League")
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 scrape 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 scrape is named as "wikitable plainrowheaders", as below. I would like to know how to scrape with table class name.
How to scrape all tables with table class named as "wikitable plainrowheaders" in a wikipedia page?
<table class="wikitable plainrowheaders" style="text-align:center;font-size:100%;">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
既然您知道表类名称,则只需更改相应的XPATH即可。
Since you know the table class name, just change the corresponding xpath.