简体   繁体   中英

Web scraping data for use in R-Studio

I am wanting to pull the data out of this server site and into R-Studio. I am new to R so not at all sure what is possible. Any help with coding to achieve this would be appreciated.

http://hbrcdata.hbrc.govt.nz/hydrotel/cgi-bin/hydwebserver.cgi/points/details?point=679&samples=true

install.packages("rvest")
library('rvest')
install.packages('XML')
library('XML')
library("httr")


#Specifying the url for desired website to be scrapped
url <- 'http://hbrcdata.hbrc.govt.nz/hydrotel/cgi- 
        bin/hydwebserver.cgi/points/samples?point=679'





webpage <- read_html(url)

tbls <- html_nodes(webpage, "table")

head(tbls)


tbls_ls <- webpage %>%
           html_nodes("table") %>%
           html_table(fill = TRUE)

tbl <- as.data.frame(tbls_ls)

View(tbl)

I have tried to fetch few other tables from the given website which is working fine.

for example:

rainfall depth:

http://hbrcdata.hbrc.govt.nz/hydrotel/cgi-bin/hydwebserver.cgi/points/details?point=63

small modification in the url as follows will fetch you actual table. rest all code reamins same ( details?point=63 as samples?point=63 )

url <- 'http://hbrcdata.hbrc.govt.nz/hydrotel/cgi-bin/HydWebServer.cgi/points/samples?point=63'

for more help you can refer the website: http://bradleyboehmke.github.io/2015/12/scraping-html-tables.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM