[問題] 使用rvest無法爬出網頁的數值

看板R_Language作者 (水中魚)時間6年前 (2018/06/06 21:36), 編輯推噓0(007)
留言7則, 2人參與, 6年前最新討論串1/2 (看更多)
[問題類型]: 程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來) [軟體熟悉度]: 新手(沒寫過程式,R 是我的第一次) [問題敘述]: 如圖 https://i.imgur.com/ifORXBa.jpg
已知方法將綠框的數字爬下來 一樣方法想把網頁中的紅框中三個數值用rvest爬蟲下來卻無法 [程式範例]: library(rvest) url <-"https://www.wantgoo.com/stock/1101?searchType=stocks" htmldata <- read_html(url) DATA1 <- htmldata %>% html_nodes(".idx-change span") %>% html_text() print(DATA1) #DATA1 可爬到我想要的數值 DATA2 <- htmldata %>% html_nodes(".labs span") %>% html_text() print(DATA2) #DATA2卻一直爬到空值 [環境敘述]: R version 3.4.4 (2018-03-15) -- "Someone to Lean On" Copyright (C) 2018 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 (64-bit) [關鍵字]: 爬蟲 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.237.133.250 ※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1528292215.A.47B.html

06/06 21:55, 6年前 , 1F
那是js,無法直接從爬蟲爬
06/06 21:55, 1F

06/06 22:11, 6年前 , 2F
c大...所以無解嗎QAQ
06/06 22:11, 2F

06/06 22:14, 6年前 , 3F
我有想試RSelenium但好像抓不到這個package了...
06/06 22:14, 3F

06/06 22:27, 6年前 , 4F

06/06 22:27, 6年前 , 5F
也不是無解,但是要研究他怎麼得到畫圖資料
06/06 22:27, 5F

06/06 22:27, 6年前 , 6F
然後直接打他的API就可以了
06/06 22:27, 6F

06/06 22:28, 6年前 , 7F
RSelenium 可以從github安裝,可以參考我上兩個推文
06/06 22:28, 7F
文章代碼(AID): #1R5-DtHx (R_Language)
文章代碼(AID): #1R5-DtHx (R_Language)