Selenium chromedriver disable logging or redirect it java(Selenium chromedriver 禁用日志记录或将其重定向 java)
问题描述
我正在尝试在迷你网络爬虫中使用 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Selenium chromedriver 禁用日志记录或将其重定向 java
基础教程推荐
- 如何使用 Java 创建 X509 证书? 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 降序排序:Java Map 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01