【问题标题】:Not able to entirely scrape HTML table using R无法使用 R 完全抓取 HTML 表
【发布时间】:2017-06-23 14:35:58
【问题描述】:

我使用了以下 R 脚本:

url="http://stats.espncricinfo.com/ci/engine/player/253802.html?class=3;orderby=default;template=results;type=batting"
check=readHTMLTable(url,header = T)
check$"Career summary"
check<-check$"Career summary"

我只能抓取前 11 个观察结果。

谁能告诉我为什么我不能刮整个桌子?

【问题讨论】:

  • 该页面上有多个表格。检查浏览器中的页面。我认为你只得到第一个 &lt;tbody&gt; 标签的内容

标签: html r web-scraping xml-parsing rvest


【解决方案1】:

获取页面上所有表格的内容:

library(XML)

url="http://stats.espncricinfo.com/ci/engine/player/253802.html?class=3;orderby=default;template=results;type=batting"

content <- htmlParse(url)

tbody <- xpathSApply(content, "//tbody")

lapply(tbody, function(x) readHTMLTable(x, header=T))

【讨论】:

    【解决方案2】:

    AS @Wietze314 说该页面上有多个表格。 您可以获取我认为您感兴趣的所有表格的列表:

    url="http://stats.espncricinfo.com/ci/engine/player/253802.html?class=3;
    orderby=default;template=results;type=batting"
    
    check=htmlParse(url)    
    
    tableNodes <- getNodeSet(check, '//tbody')
    tbList <- lapply(tableNodes, readHTMLTable)
    

    tbList 包含 22 个 data.frames 供您使用

    【讨论】:

    • Thanx @Gamba 它确实解决了我的问题。你能告诉这里的表节点是什么吗!?
    猜你喜欢
    • 2022-07-22
    • 1970-01-01
    • 2016-05-12
    • 2020-09-28
    • 2018-11-17
    • 1970-01-01
    • 1970-01-01
    • 2020-04-22
    • 1970-01-01
    相关资源
    最近更新 更多