【问题标题】:Identify web table format for scraping识别用于抓取的 Web 表格格式
【发布时间】:2020-09-11 08:44:37
【问题描述】:

这对我有用:

library(XML)
tables       <-  readHTMLTable("http://cdec.water.ca.gov/reportapp/javareports?name=FNF", as.data.frame = TRUE)
bottom_table <-  tables[[2]]
# process bottom_table's data, deploy to Shiny app

但是当我使用https 而不是http 时:

tables       <-  readHTMLTable("https://cdec.water.ca.gov/reportapp/javareports?name=FNF", as.data.frame = TRUE)
# Warning: XML content does not seem to be XML`

所以,我希望了解如何识别表格的内容类型以及用于抓取和保留表格格式的 R 库/函数。感谢您的任何提示。

【问题讨论】:

  • 我注意到 readHTMLTable() 不支持https 但是这个RCurl 解决方法成功了:stackoverflow.com/questions/25947566/…
  • 我在“http:// https:// [r] xml”上进行了搜索,第二次点击看起来可能解决了您的问题,我认为可以表述为“为什么 readHTMLTable 什么都看不到https:// 页面?”

标签: r xml rvest


【解决方案1】:

有 R 函数来确定数据帧的类和维度,这就是 readHTMLTable 期望通过您提供的 as.data.frames 参数提供的内容。

?readHTMLTable
> class(bottom_table)
#[1] "data.frame"
> dim(bottom_table)
#[1] 40  9

还有:

?rownames
?colnames

【讨论】:

  • 对于https 页面,我无法定义tablesbottom_tabletables 返回为0 的列表。
  • 第二次访问我得到的数据是:str(tables) # Named list(),所以我认为您提出问题的方式并未真正解决您面临的问题。使用 https 并且该代码会导致一个空列表,而不是一个包含任何表的对象。
猜你喜欢
  • 1970-01-01
  • 2011-08-19
  • 2021-02-22
  • 2020-09-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-07
相关资源
最近更新 更多