源码:
# 安装依赖包 if (!require(rvest)) { install.packages("rvest") } if (!require(xml2)) { install.packages("xml2") } # 引入 library(rvest) # 正文 stock_code <- "000616" year_code <- "2018" season_code <- "1" url <- paste( "http://quotes.money.164.com/trade/lsjysj_", stock_code, ".html?year=", year_code, "&season=", season_code, sep = "" ) web_page <- read_html(url) web_table <- html_table(web_page, header = TRUE, trim = TRUE, fill = TRUE)
提示:
no applicable method for 'xml_find_all' applied to an object of class "xml_document"
原因:
所要爬取的这个页面,将爬虫相关的方法禁用了。所以爬下来的是一个空的“xml_document”文档,无法进行后续的解析。