如何解决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
经过一些迭代后,我需要旋转/重置/更改代理。我可以(可能?)在 args
的 wdman::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 举报,一经查实,本站将立刻删除。