Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(httr)
- library(pipeR)
- library(xml2)
- library(rvest)
- library(ggplot2)
- library(plotly)
- tableNode <- GET("http://pchome.megatime.com.tw/rank/sto2/ock00.html",
- add_headers(Connection = "Keep-Alive", Accept = "text/html, application/xhtml+xml, */*",
- "Accept-Language" = "en-US,en;q=0.8,zh-Hans-CN;q=0.5,zh-Hans;q=0.3",
- "User-Agent" = "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko",
- referer = "http://pchome.megatime.com.tw/rank/"),
- set_cookies(stock_popup_personalnews = 1, website_viewmode="normal",
- stock_config = "YTozOntzOjc6IlN0b2NrSWQiO047czozOiJ0YWciO2k6MztzOjQ6InR5cGUiO2k6Mjt9")) %>>%
- content %>>% xml_find_all("//div[@id='bttb']") %>>% xml_find_all("table")
- if (Sys.info()[[1]] == "windows") {
- original_locale <- Sys.getlocale("LC_COLLATE")
- Sys.setlocale("LC_ALL", 'C')
- resTbl <- html_table(tableNode)[[1]]
- Sys.setlocale(locale = original_locale)
- } else {
- resTbl <- html_table(tableNode)[[1]]
- }
- names(resTbl) <- c("rank", "stock", "eps_2016Q4", "eps_2015Q4", "price", paste0("V", 1:5))
- p <- ggplot(resTbl, aes(price, eps_2016Q4, stock = stock)) + geom_point()
- ggplotly(p, tooltip = c("x", "y", "stock"))
Advertisement
Add Comment
Please, Sign In to add comment