我正在从这个页面中搜索R中的数据,http://finviz.com/screener.ashx?v=111&f=earningsdate_nextdays5显示弹出广告。这些广告会影响脚本,因此我想启用adblocker扩展程序:https://chrome.google.com/webstore/detail/adblock/gighmmpiobklfepjocnamgkkbiglidom
我在这里使用RSelenium包文档中的代码,https://cran.r-project.org/web/packages/RSelenium/RSelenium.pdf
我通过打开Chrome浏览器并导航到:chrome:// version /找到了配置文件目录。这是我通常的个人资料,其中启用了adblocker扩展程序。
但是,当我打开chrome时,没有adblocker。我查看了这个页面,http://scottcsims.com/wordpress/?p=450,他建议使用add_extension方法,该方法似乎没有在RSelenium中实现。
有关如何在R打开的浏览器中启用广告拦截器的任何想法?
我的代码到目前为止。请注意,这是在Mac上完成的,当然您的用户名将与我的用户名不同,因此请务必将getChromeProfile中的第一个参数更改为您在此页面上的“配置文件路径”中找到的内容,chrome:// version /
require(RSelenium)
RSelenium::startServer()
cprof <- getChromeProfile("/Users/<username>/Library/Application Support/Google/Chrome/", "Profile 1")
remDr <<- remoteDriver(browserName = "chrome", extraCapabilities = cprof)
remDr$open()
appURL <- "http://finviz.com/screener.ashx?v=111&f=earningsdate_nextdays5"
remDr$navigate(appURL)
这不是特别的ablock扩展,因为我更喜欢adguard,但我总是使用它:
示例下载文件路径:/Users/admin/Downloads/extension_3_0_13_0.crx
R代码:
library(RSelenium) #install_github("ropensci/RSelenium")
cprof <- list(chromeOptions =
list(extensions =
list(base64enc::base64encode("/Users/admin/Downloads/extension_3_0_13_0.crx"))
))
rD <- rsDriver(port = 4444L,extraCapabilities=cprof, browser ="chrome",chromever = "73.0.3683.68")}
#if error port used or need to clear port
#rm(rD)
#rm(remDr)
#gc() #then try again
#set timeout preferences with chrome client
remDr <- rD$client
remDr$setTimeout(type = 'page load', milliseconds = 120000)
remDr$setTimeout(type = 'implicit', milliseconds = 120000)