google-chrome - 如何在没有版本信息的情况下启动 Headless Chrome?
问题描述
我有一些运行无头 chrome 的代码,我从教程中复制了它,它运行良好。唯一的问题是它输出一些我不需要的信息:
- 在端口 28720 上启动 ChromeDriver 91.0.4472.19 (1bf021f248676a0b2ab3ee0561d83a59e424c23e-refs/branch-heads/4472@{#288})
- 只允许本地连接。
- 有关保持 ChromeDriver 安全的建议,请参阅https://chromedriver.chromium.org/security-considerations。
- ChromeDriver 已成功启动。
- 2021 年 5 月 29 日下午 1:58:56 org.openqa.selenium.remote.ProtocolHandshake createSession INFO:检测到的方言:W3C`
这会破坏我程序的输出,我该如何关闭它?
这是我的代码:...
package chromeheadlesstest;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class ChromeHeadlessTest {
public static void main(String[] args) throws IOException{
String chromeDriverPath = "F:\\Jrun\\lib\\chromedriver.exe" ;
System.setProperty("webdriver.chrome.driver", chromeDriverPath);
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless", "--disable-gpu", "--window-size=1920,1200","--ignore-certificate-errors", "--silent");
options.addArguments("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36");
WebDriver driver = new ChromeDriver(options);
driver.get("https://bbc.co.uk");
String page = driver.getPageSource();
FileWriter Details = new FileWriter("I:\\cak\\page1.html", false);
Details.write(page);
Details.close();
// Take a screenshot of the current page
File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshot, new File("screenshot.png"));
}
}
...
解决方案
推荐阅读
- kivy - text_field 未在 kivymd 中单击
- powershell - 如何将文件名基于文件夹名称的文件移动到同一文件夹中的子文件夹
- ios - 在 SwiftUI 动态表单中声明 TextField 和 Toggle
- deep-learning - Earlystopping 不适用于深度学习模型
- c# - Unity 2D C#如何在点击时制作面向对象的坐标
- string - 在 Rust 中将换行符添加到字符串(或 &str)末尾的最轻松的方法是什么?
- .htaccess - url 变量在重写规则后设置
- laravel - 将 localhost 连接到 cloudamqp 云
- laravel - 检查循环中的第一项
- python - 如何使用 dropbox python API 上传 csv 文件?