【发布时间】:2016-12-21 09:58:14
【问题描述】:
我将如何并行运行RSelenium。
以下是并行使用rvest的示例
library(RSelenium)
library(rvest)
library(magrittr)
library(foreach)
library(doParallel)
URLsPar <- c("http://www.example.com/", "http://s5.tinypic.com/n392s6_th.jpg", "http://s5.tinypic.com/jl1jex_th.jpg",
"http://s6.tinypic.com/16abj1s_th.jpg", "http://s6.tinypic.com/2ymvpqa_th.jpg")
(detectCores() - 1) %>% makeCluster %>% registerDoParallel
ws <- foreach(x = 1:length(URLsPar), .packages = c("rvest", "magrittr", "RSelenium")) %dopar% {
URLsPar[x] %>% read_html %>% as("character")}
stopImplicitCluster()
【问题讨论】:
-
使用
remoteDriver类的open方法为每个实例打开一个单独的浏览器。就您的工作流程而言,seleniumPipes可能是合适的github.com/johndharrison/seleniumPipes -
我有几千个 url,假设我在
registerDoParallel中有 3 个核心,我需要在foreach之前open3 个实例吗?我不知道seleniumPipes!谢谢
标签: r rselenium doparallel