【发布时间】: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 <- getChromeProfile("/Users/<username>/Library/Application Support/Google/Chrome", "Profile 1")。这将从 MAC 默认 chrome 配置文件目录打开配置文件Profile 1。 -
嗨,JD,这也打开了 chrome,但扩展程序没有加载。
-
要澄清您的个人资料是否为
/Users/<username>/Library/Application Support/Google/Chrome/Profile 1,您将使用getChromeProfile("/Users/<username>/Library/Application Support/Google/Chrome", "Profile 1")。如果您的个人资料位于/Users/<username>/Library/Application Support/Google/Chrome/Default,您将使用getChromeProfile("/Users/<username>/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