[英]Run yaml file for parallel selenium test from R or python
我有一个简单的yaml文件:
seleniumhub:
image: selenium/hub
ports:
- 4444:4444
firefoxnode:
image: selenium/node-firefox-debug
ports:
- 4577
links:
- seleniumhub:hub
chromenode:
image: selenium/node-chrome-debug
ports:
- 4578
links:
- seleniumhub:hub
我在docker中执行过:
docker-compose up -d
我有一个集线器和两个节点在运行。
现在我想并行运行两个非常简单的selenium命令(用RSelenium编写):
remDr$open()
remDr$navigate("http://www.r-project.org")
remDr$screenshot(display = TRUE)
我想知道如何在Python或R中并行运行selenium命令。 我尝试了几种方法但没有效果。 例如在R中:
library(RSelenium)
remDr <- remoteDriver(remoteServerAddr = "192.168.99.100", port = 4444L)
remDr$open()
remDr$navigate("http://www.r-project.org")
remDr$screenshot(display = TRUE)
什么都不做 我也试过运行两个remoteDrivers,但这对以太没有帮助:
remDr <- remoteDriver(remoteServerAddr = "192.168.99.100", port = 4577L)
remDr$open()
remDr$navigate("http://www.r-project.org")
remDr$screenshot(display = TRUE)
这是重复的
您可以使用上面的代码中的代码来执行并行执行
library(RSelenium)
library(rvest)
library(magrittr)
library(foreach)
library(doParallel)
URLsPar <- c("http://www.bbc.com/", "http://www.cnn.com", "http://www.google.com",
"http://www.yahoo.com", "http://www.twitter.com")
appHTML <- c()
(cl <- (detectCores() - 1) %>% makeCluster) %>% registerDoParallel
# open a remoteDriver for each node on the cluster
clusterEvalQ(cl, {
library(RSelenium)
remDr <- remoteDriver$new(remoteServerAddr = ip, port = port)
remDr$open()
})
myTitles <- c()
ws <- foreach(x = 1:length(URLsPar), .packages = c("rvest", "magrittr", "RSelenium")) %dopar% {
remDr$navigate(URLsPar[x])
remDr$getTitle()[[1]]
}
# close browser on each node
clusterEvalQ(cl, {
remDr$close()
})
stopImplicitCluster()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.