問題描述
我正在嘗試在迷你網絡爬蟲中使用 selenium 來獲取頁面源.我的輸出日志被 selenium 日志入侵,有沒有辦法完全禁用日志記錄或只是以某種方式將其重定向到/dev/null?
I am trying to use selenium in a mini web crawler to get the page source. My output log is invaded by selenium logs, is there a way to totally disable the logging or just redirect it in someway to /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
我通過以下方式調用驅動程序:
I am calling the driver in the following way:
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);
推薦答案
好吧,我終于擺脫了那些無用的日志記錄.這就是我所做的.
使用:System.setProperty("webdriver.chrome.silentOutput", "true");
要擺脫 chromedriver 日志:
Ok i have managed to finally get rid of that useless loggings. Here is what i did.
Use:
System.setProperty("webdriver.chrome.silentOutput", "true");
To get rid of chromedriver logs:
啟動 ChromeDriver 2.43.600233(523efee95e3d68b8719b3a1c83051aa63aa6b10d) 在端口 1628 上僅限本地允許連接.
Starting ChromeDriver 2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d) on port 1628 Only local connections are allowed.
并使用:java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.OFF);
擺脫硒日志:
And use:
java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.OFF);
To get rid of selenium logs:
2018 年 2 月 24 日下午 7:52:01 org.openqa.selenium.remote.ProtocolHandshakecreateSession INFORMAZIONI:檢測到的方言:OSS
ott 24, 2018 7:52:01 PM org.openqa.selenium.remote.ProtocolHandshake createSession INFORMAZIONI: Detected dialect: OSS
這篇關于Selenium chromedriver 禁用日志記錄或將其重定向 java的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!