其他链接:
java爬虫入门jsoup入门(简单示例,五分钟)
https://blog.youkuaiyun.com/qq_33745371/article/details/109064543
java爬虫(jsoup)实战整合mybatisPlus
https://blog.youkuaiyun.com/qq_33745371/article/details/109765252
文章目录
使用FiddlerEverywhere抓微信小程序(pc端)
1.设置fiddlerEverwhere
打勾
Capture HTTPS traffic------捕获HTTPS流量
follow redirects automatically------自动跟踪重定向
2.访问小程序,这时候注意看你的fiddler Everywhere
2.1)右键选择第一个Edit in Composer
2.2)进去之后就看见一个类似于postman的界面了
3.根据这些信息,就可以去写java代码了
我创建了一个springboot项目,习惯了,感觉方便。
3.1)引入额外的maven(okHttp和fastjson)。
<!--okHttp-->
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId>
<version>2.5.0</version>
</dependency>
<!--fastJson-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.75</version>
</dependency>
3.2)写代码
这里面其实有个问题,应该根据total/每页的总量(取余判断是否+1),算出一共要访问多少次。
假设total为105,每页20条数据,则一共需要访问6次。
结果这里的接口其实把后端所有的数据都返回过来了,所以只需要查询一次即可。
这里我写的代码就是仅查询一次的
package com.qwl.gitdemo;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.squareup.okhttp.*;
import java.io.IOException;
import java.util.HashMap;
public class ZjwzPhone {
public static void main(String[] args) throws IOException {
//url
String url = "https://lh.wzlhzj.com/web_lh/system/uidNums/list";
//请求头
HashMap<String, String> headMap = new HashMap<>();
headMap.put("Host", "lh.wzlhzj.com");
headMap.put("Content-Length", "41");
headMap.put("User-Agent", "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36 QBCore/4.0.1316.400 QQBrowser/9.0.2524.400 Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2875.116 Safari/537.36 NetType/WIFI MicroMessenger/7.0.20.1781(0x6700143B) WindowsWechat");
Headers headers = Headers.of(headMap);
//请求体
HashMap<String, String> bodyMap = new HashMap<>();
bodyMap.put("pageNum", "1");
bodyMap.put("pageSize", "20");
bodyMap.put("status", "0");
bodyMap.put("deptType", "0");
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json;charset=utf-8"), JSONObject.toJSONString(bodyMap));
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(url)//url
.headers(headers)//请求头
.post(requestBody)//请求体
.build();
Response response = null;
response = client.newCall(request).execute();
String jsonStr = response.body().string();
Object parse = JSONObject.parse(jsonStr);
JSONObject jsonObject = (JSONObject) parse;
int total = (int) jsonObject.get("total");//数据总数
System.out.println("靓号条数:"+total);
JSONArray arr = (JSONArray) jsonObject.get("rows");
for (int j = 0; j < arr.size(); j++) {
JSONObject jsonDetail = (JSONObject) arr.get(j);
//createTime 创建时间
String createTime = jsonDetail.getString("createTime");
//phone 靓号
String phone = jsonDetail.getString("phone");
//uidType 靓号级别
String uidType = jsonDetail.getString("uidType");
//preDeposit 预存款
String preDeposit = jsonDetail.getString("preDeposit");
//agreementPeriod 协议期(月)
String agreementPeriod = jsonDetail.getString("agreementPeriod");
//communicationFee 月承诺通信费
String communicationFee = jsonDetail.getString("communicationFee");
System.out.println("创建时间:"+createTime+"---靓号:"+phone+"---靓号级别:"+uidType+"---预存款:"+preDeposit+"---协议期(月):"+agreementPeriod+"---月承诺通信费:"+communicationFee);
}
}
}
结果展示:
代码下载地址
百度网盘
链接:https://pan.baidu.com/s/1fteDDooOzNKb7MNiFMQL5A
提取码:saam