首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Selenium chromedriver禁用日志记录或重定向

Selenium chromedriver禁用日志记录或重定向
EN

Stack Overflow用户
提问于 2018-10-25 01:57:42
回答 1查看 12K关注 0票数 7

我正尝试在一个迷你网络爬虫中使用selenium来获取页面源代码。我的输出日志被selenium日志入侵了,有没有办法完全禁用日志记录,或者只是以某种方式将其重定向到/dev/null?

日志记录消息如下:

代码语言:javascript
复制
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

我将通过以下方式调用驱动程序:

代码语言:javascript
复制
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);
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52975287

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档