Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 从网站中提取html表_R_Web Scraping_Rcurl - Fatal编程技术网

R 从网站中提取html表

R 从网站中提取html表,r,web-scraping,rcurl,R,Web Scraping,Rcurl,我正在尝试使用XML、RCurl包来读取以下URL的一些html表 这是我正在使用的代码 library(RCurl) library(XML) options(RCurlOptions = list(useragent = "R")) url <- "http://www.nse-india.com/marketinfo/equities/cmquote.jsp?key=SBINEQN&symbol=SBIN&flag=0&series=EQ#" wp <

我正在尝试使用XML、RCurl包来读取以下URL的一些html表

这是我正在使用的代码

library(RCurl)
library(XML)
options(RCurlOptions = list(useragent = "R"))
url <- "http://www.nse-india.com/marketinfo/equities/cmquote.jsp?key=SBINEQN&symbol=SBIN&flag=0&series=EQ#"
wp <- getURLContent(url)
doc <- htmlParse(wp, asText = TRUE) 
docName(doc) <- url
tmp <- readHTMLTable(doc)
## Required tables 
tmp[[13]]
tmp[[14]]
库(RCurl)
库(XML)
选项(rcurlpoptions=list(useragent=“R”))

url看起来他们正在使用javascript通过访问和解析一些字符串来构建页面。也许你可以抓取这些数据并将其解析出来,而不是将页面本身刮掉

不过,看起来您必须使用cURL使用适当的referer头构建请求。正如您所看到的,您不能仅仅用一个简单的请求点击ajaxGetQuote页面


您可能可以通过使用Chrome或Safari中的Web Inspector或Firefox中的Firebug来读取要输入的适当标题。

duplicate?嗨,Brandon,我想不是,如果您运行我编写的代码,您将看到我得到的是所需的表,而不是与字段相关的值,由于我猜是一些javascipt,我一直在玩它,我找不到任何必要的方式下载页面。我唯一能做的建议是设置一个chron作业,用类似wget的东西下载页面,然后让R将下载的本地文件作为目标。不过,这也可能不起作用,在将其移动到R之前,您可能必须实现某种类型的web抓取软件。