当前位置: 首页 > news >正文

Java爬虫使用JSoup获取静态资源图片

import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.FileOutputStream;/*** 获取静态图片*/public class ImageDownloader {public static void main(String[] args) throws Exception {String url = "https://www.xx.com/hot"; // 替换为你想要下载图片的网址Connection connection = Jsoup.connect(url);Document document = connection.get();Elements images = document.getElementsByTag("img");for (Element image : images) {String srcUrl = image.attr("src");if (!srcUrl.isEmpty()) {downloadImage(srcUrl);}}}private static void downloadImage(String url) throws Exception {Connection connection = Jsoup.connect(url).ignoreContentType(true);byte[] bytes = connection.execute().bodyAsBytes();int lastIndexOfSlash = url.lastIndexOf("/") + 1;String fileName = url.substring(lastIndexOfSlash);FileOutputStream outputStream = new FileOutputStream("E:\\JsoupPic\\"+fileName);outputStream.write(bytes);outputStream.close();System.out.println("已下载图片:" + fileName);}
}
http://www.lryc.cn/news/306128.html

相关文章:

  • LeetCode 2433.找出前缀异或的原始数组
  • C++面试:系统网络性能评估与优化
  • Java适配器模式 - 灵活应对不匹配的接口
  • [ai笔记12] chatGPT技术体系梳理+本质探寻
  • Elasticsearch:使用 ELSER v2 进行语义搜索
  • 智慧农业之智能物流
  • Redis主从、哨兵、Redis Cluster集群架构
  • Javascript 运算符、流程控制语句和数组
  • 电机驱动死区时间
  • 图像的压缩感知的MATLAB实现(第3种方案)
  • 高温应用中GaN HEMT大信号建模的ASM-HEMT
  • 文件上传---->生僻字解析漏洞
  • Ubuntu中Python3找不到_sqlite3模块
  • HarmonyOS4.0系统性深入开发37 改善布局性能
  • Internet协议
  • 深度学习基础(一)神经网络基本原理
  • 2024年2月22日 - mis
  • 拼接 URL(C 语言)【字符串处理】
  • 故障排除:Failed to load SQL Modules into database Cluster
  • 【超详细】HIVE 日期函数(当前日期、时间戳转换、前一天日期等)
  • [ffmpeg] x264 配置参数解析
  • GO语言基础总结
  • 飞天使-linux操作的一些技巧与知识点7-devops
  • Sora:视频生成模型作为世界模拟器
  • FairyGUI × Cocos Creator 3.x 使用方式
  • 基于Java的养生健康管理系统
  • Python课堂16——异常查找及处理
  • 任务书参考答案-模块1任务一
  • 2023最新盲盒交友脱单系统源码
  • Half-Band filter(半带滤波器)