首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用RSelenium在Chrome中启用广告阻止程序扩展

使用RSelenium在Chrome中启用广告阻止程序扩展
EN

Stack Overflow用户
提问于 2016-11-12 00:09:12
回答 1查看 619关注 0票数 5

我从显示弹出广告的页面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/

代码语言:javascript
运行
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2019-04-27 10:34:20

它不是特别的块扩展,因为我更喜欢adguard,但我总是这样使用:

从CHROME以外的浏览器下载adguard https://www.crx4chrome.com/go.php?d=4687&i=158&p=31932&s=1&l=https%3A%2F%2Fclients2.googleusercontent.com%2Fcrx%2Fblobs%2FQwAAAHF3InbmK-wFIemaY3I3BCPa0e33dMYlYToYq-WCs1jSyPlSXnr3dNv-HTinVL8eTmtbBlPjwi-hJEL5_ZnPfXkYphLdiwB7LVwS3slKcj15AMZSmuWuPGYPZfS0woRX9brTIZ8faUYQCg%2Fextension_3_0_13_0.crx

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

R代码:

代码语言:javascript
运行
复制
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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40551893

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档