【发布时间】:2022-01-16 09:37:20
【问题描述】:
我正在尝试抓取新闻网站,但无法使用 click() 方法接受“接受 cookie”弹出窗口。我可以在浏览器的 HTML 代码中看到按钮,但是当我使用 getPageSource() 方法时,按钮的代码不包括在内。
这是我的代码块
public class Webscraping {
public static void main(String[] args) throws Exception{
System.setProperty("webdriver.chrome.driver","C:\\Users\\Marvin\\Desktop\\Webscraping\\chromedriver.exe");
//Pop Up blocken
//ChromeOptions options = new ChromeOptions();
//options.addArguments("disable-popup-blocking");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
String url = "https://www.focus.de/";
driver.get(url);
Thread.sleep(5000);
//HTML Code print
System.out.println(driver.getPageSource());
}
}
【问题讨论】:
标签: java html selenium cookies