一尘不染

Selenium chromedriver禁用日志记录或将其重定向到Java

selenium

我正在尝试在小型Web搜寻器中使用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);

阅读 669

收藏
2020-06-26

共1个答案

一尘不染

好的,我终于设法摆脱了无用的日志记录。这是我所做的。
使用:
System.setProperty("webdriver.chrome.silentOutput", "true");

摆脱chromedriver日志:

在端口1628上启动ChromeDriver
2.43.600233(523efee95e3d68b8719b3a1c83051aa63aa6b10d)仅允许本地连接。

并使用:
java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.OFF);
摆脱硒记录:

ott 24,2018 7:52:01 PM org.openqa.selenium.remote.ProtocolHandshake
createSession INFORMAZIONI:检测到方言:OSS

2020-06-26