我正在尝试在 java 上使用 Selenium chromedriver 抓取网站。我无法加载该页面,因为它将我检测为机器人。谷歌 Chrome 浏览器和 chromedriver 版本是正确的。我尝试了不同的方法,但我无法加载页面。这是我的代码:
//I have a button that initializes this class
public class Bet365 {
public static WebDriver driver;
public String url = "https://www.bet365.com";
static {
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
chromeOptions.setExperimentalOption("excludeSwitches", new String[]{"enable-automation"});
chromeOptions.addArguments("--disable-extensions");
chromeOptions.addArguments("no-sandbox");
chromeOptions.setExperimentalOption("useAutomationExtension", false);
chromeOptions.addArguments("enable-automation");
chromeOptions.addArguments("window-size=1280,800");
chromeOptions.addArguments("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36");
driver = new ChromeDriver(chromeOptions);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
}
public void bet365() throws InterruptedException{
startBet365();
driver.quit();
};
public void startBet365(){
driver.get(url);
}
}
任何帮助表示赞赏,非常感谢!