1.是參考這篇文章的

https://ropensci.org/tutorials/rselenium_tutorial.html

2.先到https://selenium-release.storage.googleapis.com/index.html下載最新版的selenium-server-standalone

當時最新版是3.3.1

3.打開cmd, 輸入以下指令 : java -jar selenium-server-standalone-3.3.1.jar

開著不要關掉。

擷取.PNG

4.ChromeDriver.exe放在Chrome的安裝路徑下。

例如: chrome.exechromedriver.exe都在C:\Program Files \Google\Chrome\Application目錄下。

將此路徑C:\Program Files \Google\Chrome\Application添加到環境變量PATH的路徑中

擷取.PNG

5.接著打開R語言, 記得先安裝RSelenium

library(RSelenium)

6.連接Server

remDr <- remoteDriver(remoteServerAddr = "localhost", port = 4444, browserName = "chrome")

7.打開瀏覽器

remDr$open()

擷取.PNG

8.輸入網址看看

remDr$navigate("http://www.google.com/")

擷取.PNG

remDr$navigate("http://tw.yahoo.com/")

擷取.PNG

9.接下來的請自己嘗試吧!

控制瀏覽器回到上一頁

remDr$goBack()

到下一頁

remDr$goForward()

擷取頁面

remDr$screenshot(display = TRUE)

arrow
arrow
    文章標籤
    RSelenium 1.
    全站熱搜

    張郎屋 發表在 痞客邦 留言(0) 人氣()