ChromeWebDriver 无头浏览器完整爬到页面的逻辑内容

本文详细介绍了如何使用ChromeWebDriver配置无头模式,进行页面加载策略设置,超时管理,并抓取https://www.cnblogs.com/dk1024/p/11590510.html页面的完整HTML内容。适合Web自动化测试和爬虫开发者参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ChromeWebDriver 完整爬到页面的逻辑内容

  		/*配置基础选项*/
        ChromeOptions options = new ChromeOptions();
        /*配置页面加载策略 */
        options.setPageLoadStrategy(PageLoadStrategy.EAGER);
        /*设置无头模式*/
        options.addArguments("-headless");
        /*创建驱动*/
        ChromeDriver webDriver = new ChromeDriver(options);
        /*设置页面超时时间配置*/
        WebDriver.Timeouts timeouts = webDriver.manage().timeouts();
        timeouts.pageLoadTimeout(20, TimeUnit.SECONDS);
        /*获取页面*/
        webDriver.get("https://www.cnblogs.com/dk1024/p/11590510.html");
        /*获取页面元素*/
        WebElement webElement = webDriver.findElement(By.xpath("/html"));
        /*获取页面内容*/
        String content = webElement.getAttribute("outerHTML");
        /*完整页面html*/
        Html html = new Html(content);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值