使用RSelenium在Chrome中启用Adblocker扩展 [英] Enable Adblocker Extension In Chrome Using RSelenium

查看:110
本文介绍了使用RSelenium在Chrome中启用Adblocker扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从此页面 http://finviz中抓取数据.com/screener.ashx?v = 111& f = earningsdate_nextdays5 来显示弹出广告.这些广告会干扰脚本,因此我想启用adblocker扩展程序: https://chrome.google.com/webstore/detail/adblock/gighmmpiobklfepjocnamgkkbiglidom

I am scraping data in R from this page, http://finviz.com/screener.ashx?v=111&f=earningsdate_nextdays5 which displays popup ads. Those ads interfere with script so I'd like to enable the adblocker extension: https://chrome.google.com/webstore/detail/adblock/gighmmpiobklfepjocnamgkkbiglidom

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

I'm working with code in the RSelenium package documentation here, https://cran.r-project.org/web/packages/RSelenium/RSelenium.pdf

我通过打开chrome浏览器并导航到chrome://version/找到了配置文件目录.这是我通常启用了adblocker扩展程序的配置文件.

I found the profile directory by opening a chrome browser and navigating to: chrome://version/. This is my usual profile which has the adblocker extension enabled.

但是,当我打开Chrome浏览器时,没有adblocker.我查看了此页面, http://scottcsims.com/wordpress/?p=450并且他建议使用在RSelenium中似乎未实现的add_extension方法.

However, when I open chrome, no adblocker is there. I looked at this page, http://scottcsims.com/wordpress/?p=450 and he suggests using the add_extension method which doesn't appear to be implemented in RSelenium.

关于我如何在R打开的浏览器中启用adblocker的任何想法?

Any idea on how I can get the adblocker enabled in the browser that R opens?

到目前为止,我的代码.请注意,这是在Mac上完成的,当然您的用户名将与我的用户名不同,因此请确保将getChromeProfile中的第一个参数更改为您在此页面上的配置文件路径中找到的参数chrome://version/

My code so far. Please note, this was done on a mac and of course your username will be different than mine, so be sure to change the first argument in getChromeProfile to what you find in Profile Path on this page, 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,因此它不是完全阻止扩展,但我始终使用它:

It isn't ablock extension specifically since I like adguard better, but I always use this:

下载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

Download adguard FROM A BROWSER OTHER THAN CHROME: 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_0_13_0.crx

Example download filepath: /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 = "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)

这篇关于使用RSelenium在Chrome中启用Adblocker扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆