【问题标题】:Enable Adblocker Extension In Chrome Using RSelenium使用 RSelenium 在 Chrome 中启用 Adblocker 扩展
【发布时间】:2017-03-25 21:57:42
【问题描述】:

我正在从该页面http://finviz.com/screener.ashx?v=111&f=earningsdate_nextdays5 抓取 R 中的数据,该页面显示弹出广告。这些广告会干扰脚本,所以我想启用 adblocker 扩展: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,他建议使用似乎没有在 RSelenium 中实现的 add_extension 方法。

知道如何在 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)

【问题讨论】:

  • 应该是cprof &lt;- getChromeProfile("/Users/&lt;username&gt;/Library/Application Support/Google/Chrome", "Profile 1")。这将从 MAC 默认 chrome 配置文件目录打开配置文件 Profile 1
  • 嗨,JD,这也打开了 chrome,但扩展程序没有加载。
  • 要澄清您的个人资料是否为/Users/&lt;username&gt;/Library/Application Support/Google/Chrome/Profile 1,您将使用getChromeProfile("/Users/&lt;username&gt;/Library/Application Support/Google/Chrome", "Profile 1")。如果您的个人资料位于/Users/&lt;username&gt;/Library/Application Support/Google/Chrome/Default,您将使用getChromeProfile("/Users/&lt;username&gt;/Library/Application Support/Google/Chrome", "Default")
  • 我已更新我的示例代码以反映 cprof /Library/Application Support/Google/Chrome/", "Profile 1")。但是,只有一些扩展加载,广告拦截器不是其中之一。配置文件 1 是目录中唯一有意义的配置文件,因为我是唯一使用这台计算机的人。
  • 默认配置文件称为 Default 而不是 Profile 1(至少在 Windows 上)。为什么不为 Selenium 制作一个单独的配置文件。您的代码可以在 Windows 上运行,并且安装了 adblock 的配置文件的正确路径。 MAC 我不能说它是否有效。

标签: r google-chrome selenium rselenium


【解决方案1】:

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

从非 Chrome 浏览器下载 adguardhttps://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

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)

【讨论】:

  • 你知道怎么让它和"profile.managed_default_content_settings.images" = 2L"一起工作吗?那就是禁用图像
猜你喜欢
  • 2023-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-12
  • 2017-07-03
  • 2014-08-05
  • 2018-04-15
  • 2018-09-11
相关资源
最近更新 更多