Rvest html_table 错误 - out[j + k, ] 错误:下标越界 [英] Rvest html_table error - Error in out[j + k, ] : subscript out of bounds
本文介绍了Rvest html_table 错误 - out[j + k, ] 错误:下标越界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对用 R 抓取有点陌生,但我收到一条我无法理解的错误消息.我的代码:
I'm somewhat new to scraping with R, but I'm getting an error message that I can't make sense of. My code:
url <- "https://en.wikipedia.org/wiki/California_State_Legislature,_2017%E2%80%9318_session"
leg <- read_html(url)
testdata <- leg %>%
html_nodes('table') %>%
.[6] %>%
html_table()
我收到的回复:
out[j + k, ] 错误:下标越界
Error in out[j + k, ] : subscript out of bounds
当我用 html_text 替换 html_table 时,我没有收到错误消息.知道我做错了什么吗?
When I swap out html_table with html_text I don't get the error. Any idea what I'm doing wrong?
谢谢!
推荐答案
希望对您有所帮助!
library(htmltab)
library(dplyr)
library(tidyr)
url <- "https://en.wikipedia.org/wiki/California_State_Legislature,_2017%E2%80%9318_session"
url %>%
htmltab(6, rm_nodata_cols = F) %>%
.[,-1] %>%
replace_na(list(Notes = "", "Term-limited?" = "")) %>%
`rownames<-` (seq_len(nrow(.)))
输出为:
District Name Party Residence Term-limited? Notes
1 1 Ted Gaines Republican El Dorado Hills
2 2 Mike McGuire Democratic Healdsburg
3 3 Bill Dodd Democratic Napa
4 4 Jim Nielsen Republican Gerber
5 5 Cathleen Galgiani Democratic Stockton
6 6 Richard Pan Democratic Sacramento
...
这篇关于Rvest html_table 错误 - out[j + k, ] 错误:下标越界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文