|
@@ -2,10 +2,8 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import org.jsoup.Connection;
|
|
import org.jsoup.Connection;
|
|
|
import org.jsoup.Jsoup;
|
|
import org.jsoup.Jsoup;
|
|
|
import org.jsoup.nodes.Document;
|
|
import org.jsoup.nodes.Document;
|
|
|
-import top.lvzhiqiang.util.FileUtil;
|
|
|
|
|
import top.lvzhiqiang.util.JsoupUtil;
|
|
import top.lvzhiqiang.util.JsoupUtil;
|
|
|
|
|
|
|
|
-import java.io.BufferedInputStream;
|
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.BufferedReader;
|
|
|
import java.io.InputStreamReader;
|
|
import java.io.InputStreamReader;
|
|
|
import java.net.HttpURLConnection;
|
|
import java.net.HttpURLConnection;
|
|
@@ -23,6 +21,10 @@ public class Test4Javbus {
|
|
|
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 1080));
|
|
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 1080));
|
|
|
|
|
|
|
|
// 1 登陆获取cookies
|
|
// 1 登陆获取cookies
|
|
|
|
|
+ // 1.0 https://www.javbus.com/forum/forum.php
|
|
|
|
|
+ Connection.Response forumResponse = JsoupUtil.requestBody("https://www.javbus.com/forum/forum.php", JsoupUtil.HTTP_GET, proxy, null);
|
|
|
|
|
+ Map<String, String> forumCookies = forumResponse.cookies();
|
|
|
|
|
+ System.out.println(forumCookies);
|
|
|
// 1.1 https://www.javbus.com/forum/member.php
|
|
// 1.1 https://www.javbus.com/forum/member.php
|
|
|
String memberUrl = "https://www.javbus.com/forum/member.php";
|
|
String memberUrl = "https://www.javbus.com/forum/member.php";
|
|
|
Map<String, String> params = new HashMap<>();
|
|
Map<String, String> params = new HashMap<>();
|
|
@@ -51,50 +53,61 @@ public class Test4Javbus {
|
|
|
Map<String, String> headerParams = new HashMap<>();
|
|
Map<String, String> headerParams = new HashMap<>();
|
|
|
headerParams.put("referer", "https://www.javbus.com/forum/forum.php");
|
|
headerParams.put("referer", "https://www.javbus.com/forum/forum.php");
|
|
|
Connection.Response imgResponse = JsoupUtil.requestBody(imgVerifyUrl, JsoupUtil.HTTP_GET, proxy, headerParams, null);
|
|
Connection.Response imgResponse = JsoupUtil.requestBody(imgVerifyUrl, JsoupUtil.HTTP_GET, proxy, headerParams, null);
|
|
|
- BufferedInputStream bufferedInputStream = imgResponse.bodyStream();
|
|
|
|
|
|
|
+ byte[] imgBytes = imgResponse.bodyAsBytes();
|
|
|
// 1.4 get imgVerifyNumber by BaiduOCR
|
|
// 1.4 get imgVerifyNumber by BaiduOCR
|
|
|
|
|
+
|
|
|
|
|
+ /*//一次最多读取1k
|
|
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
|
|
+ //实际读取的长度
|
|
|
|
|
+ int readLenghth;
|
|
|
|
|
+ //创建的一个写出的缓冲流
|
|
|
|
|
+ File savePathPrexFile = new File("C:\\Users\\l1024v\\Desktop");
|
|
|
|
|
+ BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(new File(savePathPrexFile, "1.png")));
|
|
|
|
|
+ //文件逐步写入本地
|
|
|
|
|
+ BufferedInputStream bufferedInputStream = new BufferedInputStream(new ByteArrayInputStream(imgBytes));
|
|
|
|
|
+ while ((readLenghth = bufferedInputStream.read(buffer, 0, 1024)) != -1) {//先读出来,保存在buffer数组中
|
|
|
|
|
+ bufferedOutputStream.write(buffer, 0, readLenghth);//再从buffer中取出来保存到本地
|
|
|
|
|
+ }
|
|
|
|
|
+ //关闭缓冲流
|
|
|
|
|
+ bufferedOutputStream.close();
|
|
|
|
|
+ bufferedInputStream.close();*/
|
|
|
|
|
+
|
|
|
String ocrAccurateBasicUrl = "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic";
|
|
String ocrAccurateBasicUrl = "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic";
|
|
|
String accessToken = getAuth("taQYPoO9deuODxEsltkGFyqG", "lm9laVGOO14cH3sfWvtwcL1GtEC8rwS9");
|
|
String accessToken = getAuth("taQYPoO9deuODxEsltkGFyqG", "lm9laVGOO14cH3sfWvtwcL1GtEC8rwS9");
|
|
|
headerParams.clear();
|
|
headerParams.clear();
|
|
|
headerParams.put("Content-Type", "application/x-www-form-urlencoded");
|
|
headerParams.put("Content-Type", "application/x-www-form-urlencoded");
|
|
|
params.clear();
|
|
params.clear();
|
|
|
- byte[] imgBytes = FileUtil.readStreamByBytes(bufferedInputStream);
|
|
|
|
|
params.put("image", Base64.getEncoder().encodeToString(imgBytes));
|
|
params.put("image", Base64.getEncoder().encodeToString(imgBytes));
|
|
|
Connection.Response ocrResponse = JsoupUtil.requestBody(ocrAccurateBasicUrl.concat("?access_token=").concat(accessToken),
|
|
Connection.Response ocrResponse = JsoupUtil.requestBody(ocrAccurateBasicUrl.concat("?access_token=").concat(accessToken),
|
|
|
JsoupUtil.HTTP_POST, Proxy.NO_PROXY, headerParams, params);
|
|
JsoupUtil.HTTP_POST, Proxy.NO_PROXY, headerParams, params);
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(ocrResponse.body());
|
|
|
|
|
|
|
+ JSONObject crAccurateBasicResult = JSONObject.parseObject(ocrResponse.body());
|
|
|
|
|
+ String seccodeverify = crAccurateBasicResult.getJSONArray("words_result").getJSONObject(0).getString("words");
|
|
|
|
|
|
|
|
// 1.4 https://www.javbus.com/forum/member.php
|
|
// 1.4 https://www.javbus.com/forum/member.php
|
|
|
StringBuffer sbParams = new StringBuffer();
|
|
StringBuffer sbParams = new StringBuffer();
|
|
|
- sbParams.append("?mod=logging&action=login&loginsubmit=yes&handlekey=login&inajax=1&loginhash=").append(key1);
|
|
|
|
|
|
|
+ sbParams.append("?mod=logging&action=login&loginsubmit=yes&handlekey=login&loginhash=").append(key1).append("&inajax=1");
|
|
|
headerParams.clear();
|
|
headerParams.clear();
|
|
|
headerParams.put("Content-Type", "application/x-www-form-urlencoded");
|
|
headerParams.put("Content-Type", "application/x-www-form-urlencoded");
|
|
|
params.clear();
|
|
params.clear();
|
|
|
params.put("formhash", key3);
|
|
params.put("formhash", key3);
|
|
|
- params.put("referer", " https://www.javbus.com/forum/forum.php");
|
|
|
|
|
|
|
+ params.put("referer", "https://www.javbus.com/forum/forum.php");
|
|
|
params.put("loginfield", "username");
|
|
params.put("loginfield", "username");
|
|
|
params.put("username", "Tujide.lv");
|
|
params.put("username", "Tujide.lv");
|
|
|
params.put("password", "Lzq920165830.");
|
|
params.put("password", "Lzq920165830.");
|
|
|
params.put("questionid", "0");
|
|
params.put("questionid", "0");
|
|
|
params.put("answer", "");
|
|
params.put("answer", "");
|
|
|
- params.put("seccodehash", key1);
|
|
|
|
|
|
|
+ params.put("seccodehash", key2);
|
|
|
params.put("seccodemodid", "member::logging");
|
|
params.put("seccodemodid", "member::logging");
|
|
|
- params.put("seccodeverify", "");
|
|
|
|
|
|
|
+ params.put("seccodeverify", seccodeverify);
|
|
|
|
|
+
|
|
|
|
|
+ System.out.println(sbParams);
|
|
|
|
|
+ System.out.println(params);
|
|
|
|
|
|
|
|
|
|
+ Connection.Response response = JsoupUtil.requestBody(memberUrl.concat(sbParams.toString()), JsoupUtil.HTTP_POST, forumCookies, headerParams, proxy, params);
|
|
|
|
|
|
|
|
- // formhash: 6471706d
|
|
|
|
|
- //referer: https://www.javbus.com/forum/forum.php
|
|
|
|
|
- //loginfield: username
|
|
|
|
|
- //username: Tujide.lv
|
|
|
|
|
- //password: Lzq920165830.
|
|
|
|
|
- //questionid: 0
|
|
|
|
|
- //answer:
|
|
|
|
|
- //seccodehash: cSAx5OIdVjbZ
|
|
|
|
|
- //seccodemodid: member::logging
|
|
|
|
|
- //seccodeverify:
|
|
|
|
|
- Connection.Response response = JsoupUtil.requestBody(memberUrl.concat(sbParams.toString()), JsoupUtil.HTTP_POST, proxy, headerParams, params);
|
|
|
|
|
Map<String, String> cookies = response.cookies();
|
|
Map<String, String> cookies = response.cookies();
|
|
|
System.out.println(cookies);
|
|
System.out.println(cookies);
|
|
|
|
|
+ System.out.println(response.body());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static String getAuth(String ak, String sk) {
|
|
public static String getAuth(String ak, String sk) {
|
|
@@ -134,7 +147,7 @@ public class Test4Javbus {
|
|
|
String access_token = jsonObject.getString("access_token");
|
|
String access_token = jsonObject.getString("access_token");
|
|
|
return access_token;
|
|
return access_token;
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- System.err.printf("获取token失败!");
|
|
|
|
|
|
|
+ System.err.print("获取token失败!");
|
|
|
e.printStackTrace(System.err);
|
|
e.printStackTrace(System.err);
|
|
|
}
|
|
}
|
|
|
return null;
|
|
return null;
|