我从显示弹出广告的页面http://finviz.com/screener.ashx?v=111&f=earningsdate_nextdays5中抓取R中的数据。这些广告会干扰脚本,所以我想启用广告拦截扩展:https://chrome.google.com/webstore/detail/adblock/gighmmpiobklfepjocnamgkkbiglidom
我在这里使用的是RSelenium包文档中的代码,https://cran.r-project.org/web/packages/RSelenium/RSelenium.pdf
我通过打开chrome浏览器并导航到: chrome://version/找到了配置文件目录。这是我通常使用的配置文件,它启用了adblocker扩展。
然而,当我打开chrome时,那里没有广告拦截器。我看了这个页面,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)
发布于 2019-04-27 10:34:20
它不是特别的块扩展,因为我更喜欢adguard,但我总是这样使用:
示例下载文件路径: /Users/admin/Downloads/extension_3__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 = "latest"))
#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)
https://stackoverflow.com/questions/40551893
复制相似问题