【发布时间】:2017-02-07 14:31:41
【问题描述】:
我正在尝试 rbind 系列 HTML 表(来自具有相同 col 名称的不同页面),但有些页面“没有记录”,我想跳过这些页面或将 NULL 分配给数据框。
示例数据框 1
url="http://stats.espncricinfo.com/ci/engine/player/28081.html?class=2;filter=advanced;floodlit=1;innings_number=1;orderby=start;result=1;template=results;type=batting;view=match"
Batting=readHTMLTable(url)
Batting$"Match by match list"
Batting<-Batting$"Match by match list"
数据框 2
url="http://stats.espncricinfo.com/ci/engine/player/625383.html?class=2;filter=advanced;floodlit=1;innings_number=1;orderby=start;result=2;template=results;type=batting;view=match"
Batting=readHTMLTable(url)
Batting$"Match by match list"
Batting<-Batting$"Match by match list"
有几个这样的 Dataframes 有表格形式的记录,有些没有记录
当我 rbind 没有记录的时候导致最终数据帧出错
final_DF<-rbind(Dataframe1,Dataframe2)
我该如何解决这个问题!?
PS:对于每个 url 查询,我会根据我对数据框的要求添加某些列集(比如使用 cbind 的 5 个附加列)。
【问题讨论】:
标签: html r xml dataframe web-scraping