本文介绍了从网页抓取数据表和数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从网页中抓取实时流数据表和数据我试过了:

I am trying to webscrape real time streaming data tables and data from a web pageI tried:

library(XML)
webpage  <- "http://www.investing.com/indices/us-30"

tables <- readHTMLTable(webpage )
n.rows <- unlist(lapply(tables, function(t) dim(t)[1]))

tables
n.rows

但我收到一个错误.

感谢您的帮助.

推荐答案

实际上我为自己能够使用它而感到自豪(我一直在努力解决这些问题很久了....)

I'm actually proud of myself for getting this to work (I have been trying to get my head around these kinds of things for a long time now....)

library(rvest)
url4 <- "http://www.investing.com/indices/us-30-historical-data"

yourdata <- url4 %>% read_html() %>%
html_nodes(xpath = '//*[@id="results_box"]/table[1]') %>%
html_table()

yourdata <- as.data.frame(yourdata)

这篇关于从网页抓取数据表和数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 20:52
查看更多