|
@@ -4,8 +4,7 @@ import org.jsoup.Jsoup;
|
|
|
import org.jsoup.nodes.Document;
|
|
import org.jsoup.nodes.Document;
|
|
|
import top.lvzhiqiang.util.JsoupUtil;
|
|
import top.lvzhiqiang.util.JsoupUtil;
|
|
|
|
|
|
|
|
-import java.io.BufferedReader;
|
|
|
|
|
-import java.io.InputStreamReader;
|
|
|
|
|
|
|
+import java.io.*;
|
|
|
import java.net.HttpURLConnection;
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.InetSocketAddress;
|
|
import java.net.InetSocketAddress;
|
|
|
import java.net.Proxy;
|
|
import java.net.Proxy;
|
|
@@ -17,6 +16,72 @@ import java.util.Map;
|
|
|
|
|
|
|
|
public class Test4Javbus {
|
|
public class Test4Javbus {
|
|
|
public static void main(String[] args) throws Exception {
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
|
+ // setupOne();
|
|
|
|
|
+ setupTwo();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static void setupTwo() throws Exception {
|
|
|
|
|
+ File file = new File("d:\\zhiqiang.lv\\Desktop", "1.html");
|
|
|
|
|
+ Document document = Jsoup.parse(file, "UTF-8");
|
|
|
|
|
+
|
|
|
|
|
+ String avatarUrl = document.select("div.avt").select("img").attr("src");
|
|
|
|
|
+ String[] mbn0Arr = document.select("div.u_profile").select("div.cl").get(0).select("h2.mbn").get(0).text().replace("(", "").replace(")", "").split("UID:");
|
|
|
|
|
+ String nickName = mbn0Arr[0].trim();
|
|
|
|
|
+ String uid = mbn0Arr[1].trim();
|
|
|
|
|
+ String emailStatus = document.select("div.u_profile").select("div.cl").get(0).select("ul.cl").first().text().replace("郵箱狀態", "").trim();
|
|
|
|
|
+ String friendNum = document.select("div.u_profile").select("div.cl").get(0).select("ul.cl").get(1)
|
|
|
|
|
+ .select("a").get(0).text().replace("好友數", "").trim();
|
|
|
|
|
+ String replyNum = document.select("div.u_profile").select("div.cl").get(0).select("ul.cl").get(1)
|
|
|
|
|
+ .select("a").get(1).text().replace("回帖數", "").trim();
|
|
|
|
|
+ String threadNum = document.select("div.u_profile").select("div.cl").get(0).select("ul.cl").get(1)
|
|
|
|
|
+ .select("a").get(2).text().replace("主題數", "").trim();
|
|
|
|
|
+ String sex = document.select("div.u_profile").select("div.cl").get(0).select("ul.cl").get(2)
|
|
|
|
|
+ .select("li").first().text().replace("性別", "").trim();
|
|
|
|
|
+ String birthday = document.select("div.u_profile").select("div.cl").get(0).select("ul.cl").get(2)
|
|
|
|
|
+ .select("li").get(1).text().replace("生日", "").trim();
|
|
|
|
|
+ String userGroup = document.select("div.u_profile").select("div.cl").get(1).select("ul").get(0)
|
|
|
|
|
+ .select("a").text();
|
|
|
|
|
+ String onlineTime = document.select("div.u_profile").select("div.cl").get(1).select("ul").get(1)
|
|
|
|
|
+ .select("li").first().text().replace("在線時間", "").replace("小時", "").trim();
|
|
|
|
|
+ String registrationTime = document.select("div.u_profile").select("div.cl").get(1).select("ul").get(1)
|
|
|
|
|
+ .select("li").get(1).text().replace("註冊時間", "").trim();
|
|
|
|
|
+ String lastVisit = document.select("div.u_profile").select("div.cl").get(1).select("ul").get(1)
|
|
|
|
|
+ .select("li").get(2).text().replace("最後訪問", "").trim();
|
|
|
|
|
+ String lastActivityTime = document.select("div.u_profile").select("div.cl").get(1).select("ul").get(1)
|
|
|
|
|
+ .select("li").get(3).text().replace("上次活動時間", "").trim();
|
|
|
|
|
+ String lastPublishedTime = document.select("div.u_profile").select("div.cl").get(1).select("ul").get(1)
|
|
|
|
|
+ .select("li").get(4).text().replace("上次發表時間", "").trim();
|
|
|
|
|
+ String timeZone = document.select("div.u_profile").select("div.cl").get(1).select("ul").get(1)
|
|
|
|
|
+ .select("li").get(5).text().replace("所在時區", "").trim();
|
|
|
|
|
+ String usedSpace = document.select("div.u_profile").select("div.cl").get(2).select("ul").get(0)
|
|
|
|
|
+ .select("li").get(0).text().replace("已用空間", "").replace("B", "").trim();
|
|
|
|
|
+ String mileage = document.select("div.u_profile").select("div.cl").get(2).select("ul").get(0)
|
|
|
|
|
+ .select("li").get(1).text().replace("里程", "").trim();
|
|
|
|
|
+ String money = document.select("div.u_profile").select("div.cl").get(2).select("ul").get(0)
|
|
|
|
|
+ .select("li").last().text().replace("金錢", "").trim();
|
|
|
|
|
+
|
|
|
|
|
+ System.out.println(avatarUrl);
|
|
|
|
|
+ System.out.println(nickName);
|
|
|
|
|
+ System.out.println(uid);
|
|
|
|
|
+ System.out.println(emailStatus);
|
|
|
|
|
+ System.out.println(friendNum);
|
|
|
|
|
+ System.out.println(replyNum);
|
|
|
|
|
+ System.out.println(threadNum);
|
|
|
|
|
+ System.out.println(sex);
|
|
|
|
|
+ System.out.println(birthday);
|
|
|
|
|
+ System.out.println(userGroup);
|
|
|
|
|
+ System.out.println(onlineTime);
|
|
|
|
|
+ System.out.println(registrationTime);
|
|
|
|
|
+ System.out.println(lastVisit);
|
|
|
|
|
+ System.out.println(lastActivityTime);
|
|
|
|
|
+ System.out.println(lastPublishedTime);
|
|
|
|
|
+ System.out.println(timeZone);
|
|
|
|
|
+ System.out.println(usedSpace);
|
|
|
|
|
+ System.out.println(mileage);
|
|
|
|
|
+ System.out.println(money);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static void setupOne() throws Exception {
|
|
|
// 代理及TOKEN设置
|
|
// 代理及TOKEN设置
|
|
|
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));
|
|
|
|
|
|
|
@@ -24,7 +89,7 @@ public class Test4Javbus {
|
|
|
// 1.0 https://www.javbus.com/forum/forum.php
|
|
// 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);
|
|
Connection.Response forumResponse = JsoupUtil.requestBody("https://www.javbus.com/forum/forum.php", JsoupUtil.HTTP_GET, proxy, null);
|
|
|
Map<String, String> forumCookies = forumResponse.cookies();
|
|
Map<String, String> forumCookies = forumResponse.cookies();
|
|
|
- System.out.println(forumCookies);
|
|
|
|
|
|
|
+ System.out.println("forumCookies=" + 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<>();
|
|
@@ -35,7 +100,7 @@ public class Test4Javbus {
|
|
|
params.put("handlekey", "login");
|
|
params.put("handlekey", "login");
|
|
|
params.put("inajax", "1");
|
|
params.put("inajax", "1");
|
|
|
params.put("ajaxtarget", "fwin_content_login");
|
|
params.put("ajaxtarget", "fwin_content_login");
|
|
|
- String memberHtmlStr = JsoupUtil.requestDocument(memberUrl, JsoupUtil.HTTP_GET, proxy, params).html().replace("<![CDATA[", "").replace("]]>", "");
|
|
|
|
|
|
|
+ String memberHtmlStr = JsoupUtil.requestDocument(memberUrl, JsoupUtil.HTTP_GET, proxy, forumCookies, null, params).html().replace("<![CDATA[", "").replace("]]>", "");
|
|
|
Document memberDocument = Jsoup.parse(memberHtmlStr);
|
|
Document memberDocument = Jsoup.parse(memberHtmlStr);
|
|
|
String key1 = memberDocument.select("input[type='password']").first().attr("id").split("_")[1];
|
|
String key1 = memberDocument.select("input[type='password']").first().attr("id").split("_")[1];
|
|
|
String key2 = memberDocument.select("span[id^='seccode']").first().attr("id").split("_")[1];
|
|
String key2 = memberDocument.select("span[id^='seccode']").first().attr("id").split("_")[1];
|
|
@@ -47,30 +112,42 @@ public class Test4Javbus {
|
|
|
params.put("action", "update");
|
|
params.put("action", "update");
|
|
|
params.put("idhash", key2);
|
|
params.put("idhash", key2);
|
|
|
params.put("modid", "member::logging");
|
|
params.put("modid", "member::logging");
|
|
|
- Document miscDocument = JsoupUtil.requestDocument(miscUrl, JsoupUtil.HTTP_GET, proxy, params);
|
|
|
|
|
|
|
+ Document miscDocument = JsoupUtil.requestDocument(miscUrl, JsoupUtil.HTTP_GET, proxy, forumCookies, null, params);
|
|
|
String imgVerifyUrl = "https://www.javbus.com/forum/" + miscDocument.select("img[onclick]").first().attr("src");
|
|
String imgVerifyUrl = "https://www.javbus.com/forum/" + miscDocument.select("img[onclick]").first().attr("src");
|
|
|
|
|
+ System.out.println("imgVerifyUrl=" + imgVerifyUrl);
|
|
|
// 1.3 get imgVerifyUrl
|
|
// 1.3 get imgVerifyUrl
|
|
|
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, forumCookies, headerParams, null);
|
|
|
byte[] imgBytes = imgResponse.bodyAsBytes();
|
|
byte[] imgBytes = imgResponse.bodyAsBytes();
|
|
|
- // 1.4 get imgVerifyNumber by BaiduOCR
|
|
|
|
|
|
|
+ Map<String, String> imgCookies = imgResponse.cookies();
|
|
|
|
|
+ System.out.println("imgCookies=" + imgCookies);
|
|
|
|
|
+ String cookieKey4Seccode = "";
|
|
|
|
|
+ for (Map.Entry<String, String> imgCookie : imgCookies.entrySet()) {
|
|
|
|
|
+ if (imgCookie.getKey().contains("seccode")) {
|
|
|
|
|
+ cookieKey4Seccode = imgCookie.getKey();
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- /*//一次最多读取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中取出来保存到本地
|
|
|
|
|
|
|
+ // 1.4 get imgVerifyNumber by BaiduOCR
|
|
|
|
|
+ {
|
|
|
|
|
+ //一次最多读取1k
|
|
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
|
|
+ //实际读取的长度
|
|
|
|
|
+ int readLenghth;
|
|
|
|
|
+ //创建的一个写出的缓冲流
|
|
|
|
|
+ File savePathPrexFile = new File("d:\\zhiqiang.lv\\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();
|
|
|
}
|
|
}
|
|
|
- //关闭缓冲流
|
|
|
|
|
- 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");
|
|
@@ -83,7 +160,7 @@ public class Test4Javbus {
|
|
|
JSONObject crAccurateBasicResult = JSONObject.parseObject(ocrResponse.body());
|
|
JSONObject crAccurateBasicResult = JSONObject.parseObject(ocrResponse.body());
|
|
|
String seccodeverify = crAccurateBasicResult.getJSONArray("words_result").getJSONObject(0).getString("words");
|
|
String seccodeverify = crAccurateBasicResult.getJSONArray("words_result").getJSONObject(0).getString("words");
|
|
|
|
|
|
|
|
- // 1.4 https://www.javbus.com/forum/member.php
|
|
|
|
|
|
|
+ // 1.5 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&loginhash=").append(key1).append("&inajax=1");
|
|
sbParams.append("?mod=logging&action=login&loginsubmit=yes&handlekey=login&loginhash=").append(key1).append("&inajax=1");
|
|
|
headerParams.clear();
|
|
headerParams.clear();
|
|
@@ -103,11 +180,33 @@ public class Test4Javbus {
|
|
|
System.out.println(sbParams);
|
|
System.out.println(sbParams);
|
|
|
System.out.println(params);
|
|
System.out.println(params);
|
|
|
|
|
|
|
|
- Connection.Response response = JsoupUtil.requestBody(memberUrl.concat(sbParams.toString()), JsoupUtil.HTTP_POST, forumCookies, headerParams, proxy, params);
|
|
|
|
|
|
|
+ if (cookieKey4Seccode != "") {
|
|
|
|
|
+ forumCookies.put("existmag", "mag");
|
|
|
|
|
+ forumCookies.put(cookieKey4Seccode, imgCookies.get(cookieKey4Seccode));
|
|
|
|
|
+ System.out.println("forumCookies2=" + forumCookies);
|
|
|
|
|
+ }
|
|
|
|
|
+ Connection.Response loginResponse = JsoupUtil.requestBody(memberUrl.concat(sbParams.toString()), JsoupUtil.HTTP_POST, proxy, forumCookies, headerParams, params);
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, String> loginCookies = loginResponse.cookies();
|
|
|
|
|
+ System.out.println("loginCookies=" + loginCookies);
|
|
|
|
|
+ System.out.println(loginResponse.body());
|
|
|
|
|
+ for (Map.Entry<String, String> loginCookie : loginCookies.entrySet()) {
|
|
|
|
|
+ if (loginCookie.getKey().contains("ulastactivity")) {
|
|
|
|
|
+ forumCookies.put(loginCookie.getKey(), loginCookie.getValue());
|
|
|
|
|
+ } else if (loginCookie.getKey().contains("auth")) {
|
|
|
|
|
+ forumCookies.put(loginCookie.getKey(), loginCookie.getValue());
|
|
|
|
|
+ } else if (loginCookie.getKey().contains("lastcheckfeed")) {
|
|
|
|
|
+ forumCookies.put(loginCookie.getKey(), loginCookie.getValue());
|
|
|
|
|
+ } else if (loginCookie.getKey().contains("lip")) {
|
|
|
|
|
+ forumCookies.put(loginCookie.getKey(), loginCookie.getValue());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ System.out.println("loginCookies2=" + forumCookies);
|
|
|
|
|
|
|
|
- Map<String, String> cookies = response.cookies();
|
|
|
|
|
- System.out.println(cookies);
|
|
|
|
|
- System.out.println(response.body());
|
|
|
|
|
|
|
+ // 2 获取个人资料
|
|
|
|
|
+ Connection.Response memberInfoResponse = JsoupUtil.requestBody("https://www.javbus.com/forum/?355292", JsoupUtil.HTTP_GET, proxy, forumCookies, null, null);
|
|
|
|
|
+ System.out.println("memberInfoCookies=" + memberInfoResponse.cookies());
|
|
|
|
|
+ System.out.println(memberInfoResponse.body());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static String getAuth(String ak, String sk) {
|
|
public static String getAuth(String ak, String sk) {
|