关于网页中懒加载的爬取

这两天因为正在学习爬取的内容,但是遇到了网页中img中图片的懒加载,无法爬取,百度了两天,大概是因为笨没看懂别的博主写的;
我主要是做的漫画的爬取
主要是Java语言写的

public static void s() throws Exception {
	 //这里找到自己的驱动器的位置就行,我用的是谷歌
	 System.setProperty("webdriver.chrome.driver","C:\\Users\\Administrator\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe");//指定驱动路径
		WebDriver driver = new ChromeDriver();
		/**
链接根据自己的需求改就可以了
*/	
		driver.get("https://www.kuaikanmanhua.com/web/comic/176717/");
		//使用JavaScript使得页面滚动到最底下
		((JavascriptExecutor)driver).executeScript("window.scrollTo(0,document.body.scrollHeight)");
		WebElement findElement = driver.findElement(By.className("imgList"));
		List findElement2 = findElement.findElements(By.className("img"));
		for (WebElement webElement : findElement2) {
		//因为是漫画,点击只是更确定可以加载成功,可以不点击
			webElement.click();
			//时间可以改,这里表示加载一张给100毫秒的时间,防止网络不通畅加载不到
			Thread.sleep(100);
			System.out.println(webElement.getAttribute("src"));
		}
		driver.close();
	}

你可能感兴趣的:(关于网页中懒加载的爬取)