闺女要在幼儿园演讲绘本,需要找一下绘本的PPT,直接百度满眼都是XX文库,需要充值下载,故网页上研究了一下
- 打开对应ppt,加载完所有的ppt页
- F12控制台看一下页面代码,很工整,看起来标识出来的网址就是每一页图片的地址
- 尝试一下,果然
- 尝试一下,果然
那接下来的事情就好办了
3.1 尝试性js中获取这个网址
$(".main-content #page .page img").each(function(index,item){console.log($(item).attr("data-src"))})
没问题,接下来就是把这些图片下载下来了
public static void main(String[] args) {
public static void main(String[] args) {
String[] imageUrls = {
"https://file4.renrendoc.com/view/3df058b80a74037320c4e8acfd43f5b1/3df058b80a74037320c4e8acfd43f5b12.gif",
"https://file4.renrendoc.com/view/3df058b80a74037320c4e8acfd43f5b1/3df058b80a74037320c4e8acfd43f5b13.gif"
};
String destinationFolder = System.getProperty("user.home") + "/Desktop/图片/";
try {
Path destinationPath = Path.of(destinationFolder);
Files.createDirectories(destinationPath);
for (String imageUrl : imageUrls) {
URL url = new URL(imageUrl);
InputStream inputStream = url.openStream();
String fileName = imageUrl.substring(imageUrl.lastIndexOf("/") + 1);
Path filePath = destinationPath.resolve(fileName);
Files.copy(inputStream, filePath, StandardCopyOption.REPLACE_EXISTING);
System.out.println("图片已成功下载到:" + filePath);
}
} catch (IOException e) {
e.printStackTrace();
}
}
可能的改进
- 可以通过selenium从java中执行jQuery,省去手动获取的步骤(但是需要注意网页加载完之后需要点完"继续免费阅读"确保图片都加载,此处不再赘述)
- 可以尝试swing简单添加前台页面,打包给孩他娘,一劳永逸解决以后绘本PPT下载问题