当前位置:网站首页>使用Jsoup提取接口中的图片
使用Jsoup提取接口中的图片
2022-06-26 03:59:00 【躺着数星星】
导入依赖
<!--爬虫-->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.10.2</version>
</dependency>
使用hutool工具解析json数据
@GetMapping("/pachou")
@ApiOperation("爬虫")
public String teamMessage() {
// s = HttpUtil.get("https://china.nba.cn/stats2/season/conferencestanding.json?");
s = HttpUtil.get("https://china.nba.cn/stats2/league/playerlist.json");
return s;
}
提取并保存在磁盘中
@PostMapping("/addBatch2")
@ApiOperation(value = "批量插入")
public Result addBatch2(@RequestBody String str) throws IOException, InterruptedException {
JSONArray jsonArray = JSONArray.parseArray(str);
FileOutputStream outputStream =null;
// FileInputStream inputStream =null;
InputStream inputStream=null;
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject jsonObject = JSONObject.parseObject(jsonArray.get(i).toString());
String playerProfile = jsonObject.getString("playerProfile");
String teamProfile = jsonObject.getString("teamProfile");
JSONObject object = JSONObject.parseObject(playerProfile);
JSONObject object2 = JSONObject.parseObject(teamProfile);
// System.out.println(object.getString("displayName"));
// System.out.println(object2.getString("city"));
String playerImg = object.getString("playerId");
String displayName = object.getString("displayName");
System.out.println(playerImg);
try {
String url="https://res.nba.cn/media/img/players/head/260x190/"+playerImg+".png";
URL imgsrcUrl = new URL(url);
URLConnection connection = imgsrcUrl.openConnection();
inputStream = connection.getInputStream();
String path="F:\\chenchao\\NBA\\"+displayName+".png";
outputStream = new FileOutputStream(path);
byte[] bytes = new byte[1024];
int len = 0;
while((len=inputStream.read(bytes))!=-1){
outputStream.write(bytes,0,len);
}
System.out.println("下载完成");
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
return Result.success();
}
效果
边栏推荐
- 捕获数据包(Wireshark)
- In 2022, what professional competitions can college students majoring in automation, electrical engineering and automation participate in?
- Detr3d multi 2D picture 3D detection framework
- Prism framework
- Concept and implementation of QPS
- 使用SOAPUI访问对应的esb工程
- Lua语法讲解
- 2022.6.23-----leetcode. thirty
- What does virtualization mean? What technologies are included? What is the difference with private cloud?
- Spark - 一文搞懂 parquet
猜你喜欢
![[LOJ 6718] nine suns' weakened version (cyclic convolution, arbitrary modulus NTT)](/img/fd/0c299b7cc728f2d6274eea30937726.png)
[LOJ 6718] nine suns' weakened version (cyclic convolution, arbitrary modulus NTT)

Open Camera异常分析(一)

如何解决 Iterative 半监督训练 在 ASR 训练中难以落地的问题丨RTC Dev Meetup

The stc-isp burning program for 51 single chip microcomputer always shows that "the target single chip microcomputer is being detected..." the cold start board does not respond

YOLOv5改进:更换骨干网(Backbone)

Spark - understand parquet

用eclipse连mysql数据库出错然后出现图中的话是咋回事呀

An error occurred using the connection to database 'on server' 10.28.253.2‘

ABP framework Practice Series (I) - Introduction to persistence layer

Intelligent manufacturing learning videos and books
随机推荐
Capture packets (Wireshark)
外包干了四年,人直接废了。。。
The style of the mall can also change a lot. DIY can learn about it
【Flink】Flink 批处理模式Map端数据聚合 NormalizedKeySorter
But the Internet began to have a new evolution and began to appear in a new state
Restful API interface design standards and specifications
軟件調試測試的十大重要基本准則
Custom parameter QR code picture combined with background picture to generate new picture node environment
【QT】资源文件导入
asp.net网页选择身份进行登录的简单代码,asp连接数据库,使用asp:Panel、asp:DropDownList控件
Nepal graph learning Chapter 3_ Multithreading completes 6000w+ relational data migration
QPS的概念和实现
169. most elements
机器学习笔记 - 时间序列的趋势分量
面了个字节拿25k出来的测试,算是真正见识到了基础的天花板
Use soapUI to access the corresponding ESB project
软件调试测试的十大重要基本准则
Chrome page recording and playback function
商城风格也可以很多变,DIY 了解一下
Detailed explanation of widget construction process of fluent