MyEdgeDriver.java
1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.canrd.webmagic.processor.driver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.springframework.stereotype.Component;
import java.time.Duration;
/**
* @author zhongnanhuang
* @version 1.0
* @project webmagic-canrd-service
* @description 火狐浏览器驱动
* @date 2024/5/23 10:45:50
* 驱动下载地址:https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/?form=MA13LH#downloads
*/
@Component
public class MyEdgeDriver implements BrowserDriver{
private static final String WIN_DRIVER_PATH = "D:\\driver\\edge\\msedgedriver.exe";
private static final String LINUX_DRIVER_PATH = "/home/canrd/webmagic/chrome/chromedriver-linux64/chromedriver";
@Override
public WebDriver getDriver() {
// 设置 Chrome 驱动程序路径
System.setProperty("webdriver.edge.driver", WIN_DRIVER_PATH); // 替换为实际的驱动程序路径
// 初始化 ChromeOptions 对象
EdgeOptions options = new EdgeOptions();
// options.setPageLoadTimeout(Duration.ofSeconds(30)); // 设置页面加载超时时间为30秒
// options.addArguments("--blink-settings=imagesEnabled=false"); // 禁用图片加载
// options.addArguments("--disable-notifications"); // 禁用浏览器通知
// options.addArguments("--disable-infobars"); // 禁用信息栏
// options.addArguments("--disable-extensions"); // 禁用扩展
// options.addArguments("--disable-dev-shm-usage"); // 禁用/dev/shm使用
// options.setHeadless(true);
// 设置其他选项,例如添加扩展程序等
// 初始化 WebDriver
EdgeDriver driver = new EdgeDriver(options);
return driver;
}
}