【发布时间】:2019-03-29 05:46:12
【问题描述】:
我正在尝试在迷你网络爬虫中使用 selenium 来获取页面源。我的输出日志被 selenium 日志入侵,有没有办法完全禁用日志记录或只是以某种方式将其重定向到 /dev/null?
日志消息如下:
Starting ChromeDriver 2.43.600233
(523efee95e3d68b8719b3a1c83051aa63aa6b10d) on port 1628
Only local connections are allowed.
ott 24, 2018 7:52:01 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFORMAZIONI: Detected dialect: OSS
我通过以下方式调用驱动程序:
WebDriver driver = null;
try {
System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setBinary("/usr/bin/chromium");
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("--silent");
chromeOptions.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);
driver = new ChromeDriver(chromeOptions);
/*FirefoxBinary firefoxBinary = new FirefoxBinary();
firefoxBinary.addCommandLineOptions("--headless");
System.setProperty("webdriver.gecko.driver", "/usr/local/bin/geckodriver");
System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null");
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setBinary(firefoxBinary);
FirefoxDriver driver = new FirefoxDriver(firefoxOptions);*/
if(driver!=null) {
driver.get(link);
【问题讨论】:
-
也许你应该看看这个thread
-
好吧,可以去掉:
Starting ChromeDriver 2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d) on port 1628 Only local connections are allowed.使用:System.setProperty("webdriver.chrome.silentOutput", "true");但是ott 24, 2018 7:52:01 PM org.openqa.selenium.remote.ProtocolHandshake createSession INFORMAZIONI: Detected dialect: OSS还在。
标签: java selenium logging selenium-chromedriver