简体   繁体   中英

RSelenium and Chrome

I couldn't open Chrome with help Rselenium. When I am using Firefox all works fine. Already tried to install chromedriver for 77 ( https://chromedriver.storage.googleapis.com/index.html?path=77.0.3865.10/ ) due to below error:

Selenium message:session not created: This version of ChromeDriver only supports Chrome version 77
Build info: version: '4.0.0-alpha-2', revision: 'f148142cf8', time: '2019-07-01T21:30:10'
System info: host: 'DESKTOP-L8K5E4H', ip: 'xxx', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_211'
Driver info: driver.version: unknown
remote stacktrace: Backtrace:

I followed steps included in post under link: How to open Google Chrome with RSelenium?

Code from link:

library("RSelenium")
startServer()
mybrowser <- remoteDriver(browserName = "chrome")
mybrowser$open()

My code:

library("RSelenium")
    rD <- rsDriver(port=4444L,browser="chrome")
    mybrowser <- remoteDriver(browserName = "chrome") 
    mybrowser$open()

Both works wrongly. I still receive error like at the beggining connected with wrong chromedriver version. I am looking for solutions to run app on chrome. My Google Chrome version 76.0.3809.132 (64 bits)

You can avoid such and similar issues with RSelenium by running the browser in a Docker container. Then you don't need any drivers and chances are higher that your code will work in the future. This is especially recommended when you use macOS. The operating system has obstacles in place to prevent remote control of a browser for security reasons.

  1. Download and install Docker.

  2. Pull a Docker image of Chrome by entering the following command in the Terminal.

     docker pull selenium/standalone-chrome -debug

    You should now see “standalone-chrome” under “Images” in Docker. On the image click “Run” to create a new container. Select “Optional Setting”, set the “Local Host” to 4445, and add a second port with “+”, setting it to 5899. Run it.

  3. For Web scraping it is often necessary to see how the browser behaves. To see inside a Docker container, install the VNC Viewer. Then launch the VNC Viewer and connect to “127.0.0.1:5899” while the Docker container is running. The password is “secret” by default.

  4. Install RSelenium and execute the following four lines. You can see whether it worked by looking inside the container with the VNC Viewer. You should see the website of your choice.

     library(RSelenium) remDr <- rsDriver(port=4445L) remDr$open() remDr$navigate(url)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM