Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
535 views
in Technique[技术] by (71.8m points)

r - RSelenium: server signals port is already in use

I'm using the following code in RSelenium to open a browser. After I close the browser, or even close the handler by running remDr$close(), the port is still in use. I have to go to the terminal and manually kill the process so that the same port becomes available. Is there any automated way such that RSelenium makes the port free after it finishes scraping?

So here is my code:

library(RSelenium)
rD <- rsDriver(verbose = FALSE,port=4444L)
remDr <- rD$client
remDr$close()

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The process is composed of two parts a server (the Selenium Server) and a client (the browser you initiate). The close method of the remoteDriver class closes the client (the browser). The server also needs to be stopped when you are finished.

To stop the server when you are finished:

library(RSelenium)
rD <- rsDriver(verbose = FALSE,port=4444L)
remDr <- rD$client
remDr$close()

Now either explicitly stop the server:

rD$server$stop()

or if the rD object is removed the server will be stopped upon garbage collection:

library(RSelenium)
rD <- rsDriver(verbose = FALSE,port=4444L)
remDr <- rD$client
remDr$close()
rm(rD)
gc()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...