Last active
November 28, 2016 22:59
-
-
Save martinctc/d3d6a11683176c1abd46d3c2f0ba3a24 to your computer and use it in GitHub Desktop.
Scraper for tables on websites
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("rvest") | |
url <- "https://bank.hangseng.com/1/2/rates/foreign-currency-tt-exchange-rates" | |
#Replace xpath with bits highlighting whole table on website using 'Inspect' | |
forex <- url %>% | |
html() %>% | |
html_nodes(xpath='//*[@id="viewns_7_0G3UNU10SD0MHTI7BJ91000000_:Display"]/div[1]/table') %>% | |
html_table() | |
forex <- forex[[1]] | |
url2 <- "https://bank.hangseng.com/1/2/rates/gold-prices" | |
gold <- url2 %>% | |
html() %>% | |
html_nodes(xpath='//*[@id="viewns_7_0G3UNU10SD0MHTI7G5I0000000_:Display"]/div/table') %>% | |
html_table() | |
gold<- gold[[1]] | |
timeform <- format(Sys.time(),"%Y-%m-%d,%H%M%S") | |
output_fx<-paste("Forex",timeform,".csv") | |
write.csv(forex,file=output_fx) | |
output_gold<-paste("Gold",timeform,".csv") | |
write.csv(gold,file=output_gold) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment