【问题标题】:R: readr: is it possible to read HTML tables using this package [closed]R:readr:是否可以使用此包读取 HTML 表格 [关闭]
【发布时间】:2016-05-24 20:15:28
【问题描述】:

我想知道我们是否可以使用带有发布 html 表的页面的 url 的 readr 包访问 html 表。比如我想把page上的表导入R中。

【问题讨论】:

  • 如果您不打算离开 Hadleyland,您需要 rvest。但是XML::readHTMLTable() 会读懂那个婴儿,就像一个chizamp。
  • 你读过the description吗? “从磁盘(或连接)读取平面/表格文本文件。”

标签: r readr


【解决方案1】:

我不确定“chizamp”可能是什么,但 Scriven 是正确的,尽管需要进行一些额外的思考才能确定 XML::readHTMLTables 返回的多个表中的哪一个可能是您想要的:

> library(XML)
> help(pack=XML)
> sports <- readHTMLTable("http://sports.yahoo.com/nfl/stats/byteam?group=Offense&cat=Total&conference=NFL&year=season_2010&sort=530&old_category=Total&old_group=Offense")
> str(sports[[1]])
'data.frame':   1 obs. of  2 variables:
 $ V1: Factor w/ 1 level "": 1
 $ V2: Factor w/ 1 level "Search SportsSearch Web": 1
> str(sports[[2]])
'data.frame':   2 obs. of  1 variable:
 $ : Factor w/ 2 levels "","Sortable Stats": 2 1
> length(sports)
[1] 8
> str(sports[[8]])
 NULL
# top of str() on the seventh item in that list
str(sports[[7]])
'data.frame':   32 obs. of  28 variables:
 $ Team     : Factor w/ 32 levels "Arizona Cardinals",..: 19 26 24 14 2 23 21 9 13 12 ...
 $          : Factor w/ 1 level "": 1 1 1 1 1 1 1 1 1 1 ...
 $ G        : Factor w/ 1 level "16": 1 1 1 1 1 1 1 1 1 1 ...
 $          : Factor w/ 1 level "": 1 1 1 1 1 1 1 1 1 1 ...
 $ Pts/G    : Factor w/ 28 levels "12.3","16.9",..: 28 27 26 25 24 23 22 22 21 20 ...

【讨论】:

  • 可以直接到第七桌which = 7
  • 是的,但前提是你知道这将是第七个。
猜你喜欢
  • 2018-02-08
  • 1970-01-01
  • 1970-01-01
  • 2018-11-20
  • 2012-02-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多