webscraping data tables and data from a web page

我与影子孤独终老i 提交于 2021-02-07 10:53:49

问题


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

but I get an error.

Thank you for your help.


回答1:


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)


来源:https://stackoverflow.com/questions/40909966/webscraping-data-tables-and-data-from-a-web-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!