phantomjs + Selenium 重置代理

问题描述

我使用 wdman 库中的 phantomjs 和 Rselenium::remoteDriver()(我不使用 docker,因为我不熟悉)从特定网站提取一些数据。

pDrv <- wdman::phantomjs(port = 4570L,retcommand = F,check = F,args = c(sprintf('--proxy=%s:%s',"ip","port"),# 
                                  sprintf('--proxy-type=%s',"http"),sprintf('--ssl-protocol=%s',"any"),sprintf('--proxy-auth=%s:%s',"login","pass"))
                         ) 

remDr <- remoteDriver(browserName = "phantomjs",port = 4570L,extraCapabilities = eCap) # some settings

经过一些迭代后,我需要旋转/重置/更改代理。我可以(可能?)在 argswdman::phantomjs 内设置代理,但是,问题是第一次实现后 port = 4570L 会很忙,所以我需要指定另一个(例如 4571L)或杀死/停止当前的。目前我使用第二种解决方案,我只是在 cmd 命令中杀死当前的 phantomjs 进程,但它似乎相当昂贵。

shell(sprintf("netstat -ano | findstr %d",4570L),intern = T) %>%
subset(.,grepl("LISTENING",.)) %>%
str_extract(.,"\\d+$") -> PID_current_sessio

system(sprintf("taskkill /PID %d /F",as.numeric(PID_current_sessio)),invisible = T) 

我的问题是如何将新代理服务器设置为已经在运行 phantomjs 进程而不杀死当前的 phantomjs 进程?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)