使用 RSelenium 在 Chrome 中启用 Adblocker 扩展

2023-11-29

我正在从这个页面抓取 R 中的数据,显示弹出广告。这些广告会干扰脚本,因此我想启用广告拦截器扩展:https://chrome.google.com/webstore/detail/adblock/gighmmpiobklfepjocnamgkkbiglidom

我正在使用 RSelenium 包文档中的代码,https://cran.r-project.org/web/packages/RSelenium/RSelenium.pdf

我通过打开 Chrome 浏览器并导航到:chrome://version/ 找到了配置文件目录。这是我常用的配置文件,启用了广告拦截器扩展。

但是,当我打开 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)

它不是一个块扩展,因为我更喜欢 adguard,但我总是使用它:

下载广告卫士从 Chrome 以外的浏览器:

下载文件路径示例:/Users/admin/Downloads/extension_3_0_13_0.crx

R Code:

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)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 RSelenium 在 Chrome 中启用 Adblocker 扩展 的相关文章

随机推荐