【发布时间】:2020-04-19 23:01:03
【问题描述】:
我正在尝试使用 R 中的 rvest 库来抓取此 Wiki 页面的内容
(https://en.wikipedia.org/wiki/List_of_Bollywood_films_of_2019)
我想提取 4 个表格,其中包含 2019 年(1 月至 3 月、4 月至 6 月、7 月至 9 月、10 月至 12 月)宝莱坞电影的上映数据
已经完成了
library(rvest)
url <- "https://en.wikipedia.org/wiki/List_of_Bollywood_films_of_2019"
webpage <- read_html(url)
tbls <- html_nodes(webpage, "table")
#Then I match with the word opening & I get 4 tables as in wikipedia page, however I am struggling to combine them into one dataframe & store it
tbls[grep("Opening",tbls,ignore.case = T)]
这会出错
df <- html_table(tbls[grep("Opening",tbls,ignore.case = T)],fill = T)
我明白,因为它返回了多个表,我在某个地方缺少一些下标,不确定在哪里。救命!
【问题讨论】:
-
This question 似乎很有帮助。
-
如该链接和documentation 的第 8 页中所示,对于 html_table 有这样的期望:没有单元格跨越多行
标签: r web-scraping tidyverse rvest