从网页抓取数据表和数据 [英] webscraping data tables and data from a web page

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

问题描述

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

I am trying to webscrape real time streaming data tables and data from a web page I 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)

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆