From b02e9f81fb1bd045d5eb36d53bc9e1130e15b94b Mon Sep 17 00:00:00 2001 From: bit4woo Date: Thu, 11 Apr 2024 15:41:00 +0800 Subject: [PATCH] update --- src/InternetSearch/Client/QuakeClient.java | 16 +++++++-------- src/Tools/JSONHandler.java | 23 ++++++++++------------ 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/InternetSearch/Client/QuakeClient.java b/src/InternetSearch/Client/QuakeClient.java index cb70e7ad..97a7ab7c 100644 --- a/src/InternetSearch/Client/QuakeClient.java +++ b/src/InternetSearch/Client/QuakeClient.java @@ -39,7 +39,6 @@ public List parseResp(String respbody) { SearchResultEntry entry = new SearchResultEntry(); - entry.getIPSet().add(entryitem.getString("ip")); entry.setRootDomain(entryitem.getString("domain")); @@ -89,7 +88,8 @@ public boolean hasNextPage(String respbody,int currentPage) { int size = 500; ArrayList result = JSONHandler.grepValueFromJson(respbody, "total"); if (result.size() >= 1) { - int total = Integer.parseInt(result.get(0)); + int total = Integer.parseInt(result.get(result.size()-1)); + //取最后一个值,因为返回数据包中这部分信息在末尾 if (total > currentPage * size) {//size=500 return true; } @@ -113,12 +113,12 @@ public byte[] buildRawData(String searchContent, int page) { int start = size*(page-1); String body; String raw; - + if (searchContent.startsWith(SearchType.IconHash)) { searchContent = searchContent.substring(SearchType.IconHash.length()); - + body = "{\"favicon_hash\": \"%s\",\"similar\": 0.9, \"start\": %s, \"size\": %s}"; - + raw = "POST /api/v3/query/similar_icon/aggregation HTTP/1.1\r\n" + "Host: quake.360.net\r\n" + "User-Agent: curl/7.81.0\r\n" @@ -128,11 +128,11 @@ public byte[] buildRawData(String searchContent, int page) { + "Content-Length: %s\r\n" + "\r\n" + "%s"; - + }else { body = "{\"query\": \"%s\",\"start\": %s, \"size\": %s}"; - + raw = "POST /api/v3/search/quake_service HTTP/1.1\r\n" + "Host: quake.360.net\r\n" + "User-Agent: curl/7.81.0\r\n" @@ -145,7 +145,7 @@ public byte[] buildRawData(String searchContent, int page) { + "%s"; } //必须包含Content-Length,否则服务端报错 - + body = String.format(body,searchContent,start,size); raw = String.format(raw, key, body.length(),body); diff --git a/src/Tools/JSONHandler.java b/src/Tools/JSONHandler.java index c7e1c6ba..168f393e 100644 --- a/src/Tools/JSONHandler.java +++ b/src/Tools/JSONHandler.java @@ -22,11 +22,7 @@ public static void main(String args[]) { //org.json public static boolean isJSON(String test) { - if (isJSONObject(test) || isJSONArray(test)) { - return true; - }else { - return false; - } + return isJSONObject(test) || isJSONArray(test); } //org.json @@ -49,11 +45,11 @@ public static boolean isJSONArray(String test) { } } - public static ArrayList grepValueFromJson(String jsonString,String toFind) throws Exception { + public static ArrayList grepValueFromJson(String jsonString,String keyName) throws Exception { ArrayList result = new ArrayList(); if(jsonString.startsWith("HTTP/") && jsonString.contains("\r\n\r\n")) {//response - String[] parts = jsonString.split("\r\n\r\n", 1); + String[] parts = jsonString.split("\r\n\r\n", 2); if (parts.length ==2) { jsonString = parts[1]; } @@ -67,24 +63,24 @@ public static ArrayList grepValueFromJson(String jsonString,String toFin String key = (String) iterator.next(); String value = obj.get(key).toString(); - if (key.equals(toFind)) { + if (key.equals(keyName)) { result.add(value); } - result.addAll(grepValueFromJson(value,toFind)); + result.addAll(grepValueFromJson(value,keyName)); } }else if(isJSONArray(jsonString)){ //JSONArray中每个元素都是JSON JSONArray obj = new JSONArray(jsonString); for (int i=0;i grepValueFromJson(String jsonString,String toFin return result; } + public static void test() { String aaa = "[\r\n" + " {\r\n" +