Enable Adblocker Extension In Chrome Using RSeleni

2019-02-27 03:09发布

问题:

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

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

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.

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.

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

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)