SeleniumConfig.java
1.42 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
package com.canrd.webmagic.config;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author: xms
* @description: TODO
* @date: 2024/4/26 14:37
* @version: 1.0
*/
@Configuration
public class SeleniumConfig {
// @Bean
public WebDriver webDriver() throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "D:\\chrome\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");
// 初始化ChromeOptions
ChromeOptions options = new ChromeOptions();
// 添加代理,这里使用的代理是示例,需要替换为实际的代理服务器地址和端口
// options.addArguments("--proxy-server=http://proxy-server:port");
// 禁用JavaScript,有时这能帮助绕过Cloudflare的检查
options.addArguments("--disable-javascript");
// 禁用浏览器扩展,如果知道Cloudflare使用了特定的扩展,可以禁用它
options.addArguments("--disable-extensions");
// 禁用本地缓存,确保每次访问都从服务器获取
options.addArguments("--disable-application-cache");
options.setBinary("D:\\chrome\\chrome-win64\\chrome-win64\\chrome.exe");
return new ChromeDriver(options);
}
}