尝试通过从数据库传递URL来抓取数据,但抛出错误

时间:2018-05-21 10:02:28

标签: r rvest

我通过从数据库传递URL并解析为R.Below是我的代码来从网站抓取数据

base_url_2 <- sqldf('select ORG_IMMEDIATE_PARENT_SRC from OA_output where row_id=1 ')


df <- lapply(base_url_2,function(u)

    {
    try({

        html_obj <- read_html(u)
        draft_table <- html_nodes(html_obj,'table') 
        cik <- substr(u,start = 41,stop = 47) 
        draft1 <- html_table(draft_table,fill = TRUE) 
        final <- c(cik,draft1) 

    })
})


check <- sapply(df, class) != "try-error"
df <- df[check] 


data <- melt(df)
data <- as.data.frame(data,row.names = NULL)
data <- data[,1:2]
names(data) <- c("CIK","Company") 

data2 <- transform(data, CIK = na.locf(CIK ))

options(max.print = 5.5e5)

当我尝试运行上面的代码时,会抛出以下错误:

  

doc_parse_file出错(con,encoding = encoding,as_html = as_html,   options = options):期望单个字符串值:[type = character;   程度= 455]。

请帮我解释一下代码

0 个答案:

没有答案