Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(installr)
- library(stringi)
- library(stringr)
- library(rvest)
- library(httr)
- library(pipeR)
- if (is.windows()) {
- backupLocale <- Sys.getlocale("LC_COLLATE")
- Sys.setlocale("LC_ALL", 'C')
- }
- htmlTbl <- GET("http://goodinfo.tw/StockInfo/StockFinDetail.asp",
- query = list(RPT_CAT = "IS_M_QUAR_ACC", STOCK_ID = "2412")) %>>%
- read_html %>>% html_node("table.solid_1_padding_3_4_tbl") %>>% html_table(fill = TRUE)
- if (is.windows()) {
- htmlTbl <- lapply(htmlTbl, function(v){
- if (class(v) == "character") {
- return(stri_conv(str_replace_all(v, " |\\s", ""), to = "big5")) # 字串都轉成big5
- } else {
- return(v)
- }
- }) %>>% `names<-`(NULL) %>>% as.data.frame %>>% # names一定要先清空不然會錯
- `names<-`(stri_conv(names(htmlTbl), to = "big5"))
- Sys.setlocale(locale = backupLocale)
- }
Advertisement
Add Comment
Please, Sign In to add comment