【发布时间】:2020-04-13 07:03:25
【问题描述】:
我正在尝试使用在 Heroku 上的 Spring Boot 应用程序中运行的无头硒来抓取一些 twitter 数据。我的 Heroku 应用程序中包含以下 2 个构建包:
1) https://github.com/heroku/heroku-buildpack-chromedriver.git
2) https://github.com/heroku/heroku-buildpack-google-chrome.git
这两个构建包专为在 heroku 应用中运行无头硒而设计。 在 selenium 脚本输入我的 twitter 登录数据并点击登录按钮后,我的脚本不断崩溃。为什么?我检查了页面源,从 twitter 中发现了以下提示:
我们检测到您的浏览器禁用了 JavaScript。你会 想继续使用旧版 Twitter?
很明显,javascript 似乎被禁用了,这非常糟糕。而且我不想继续使用旧模式(没有 javascript)。
在初始化 webdriver 时,我尝试了以下两个选项来确保启用了 javascript。但似乎被忽略了:
选项 1)
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless", "--enable-javascript");
WebDriver webdriver = ChromeDriver(chromeOptions);
选项2)
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setJavascriptEnabled(true);
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
WebDriver webdriver = ChromeDriver(capabilities);
有什么想法吗?
【问题讨论】:
标签: java google-chrome selenium-webdriver heroku google-chrome-headless