【问题标题】:Scraping a specific table from a webpage using R使用 R 从网页中抓取特定表格
【发布时间】:2013-11-16 18:57:46
【问题描述】:

我需要从以下 URL 中提取一个表格: http://stats.espncricinfo.com/ci/engine/records/team/match_results.html?class=2;id=2013;type=year

我只需要标题为“匹配结果”的表格

我使用了以下代码: 库(XML) ODItable http://stats.espncricinfo.com/ci/engine/records/team/match_results.html?class=2;id=2013;type=year')

如何从此处提取特定表?

【问题讨论】:

    标签: r xml web-scraping


    【解决方案1】:

    你几乎拥有它!

    library(XML) 
    url <- 'http://stats.espncricinfo.com/ci/engine/records/team/match_results.html?class=2;id=2013;type=year'
    ODItable <- readHTMLTable(url)
    head(ODItable$`Match results`)
    
         Team 1    Team 2    Winner    Margin    Ground   Match Date  Scorecard
    1     India  Pakistan  Pakistan   85 runs   Kolkata  Jan 3, 2013 ODI # 3315
    2     India  Pakistan     India   10 runs     Delhi  Jan 6, 2013 ODI # 3316
    3 Australia Sri Lanka Australia  107 runs Melbourne Jan 11, 2013 ODI # 3317
    4     India   England   England    9 runs    Rajkot Jan 11, 2013 ODI # 3318
    5 Australia Sri Lanka Sri Lanka 8 wickets  Adelaide Jan 13, 2013 ODI # 3319
    6     India   England     India  127 runs     Kochi Jan 15, 2013 ODI # 3320
    

    【讨论】:

    • 谢谢斯科特,这很有帮助!
    • @RRookie 如果这回答了你的问题,你能接受这个答案吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-03
    • 1970-01-01
    • 2018-10-15
    • 2016-10-19
    • 1970-01-01
    • 2021-05-31
    • 1970-01-01
    相关资源
    最近更新 更多