Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bit4woo committed Apr 11, 2024
1 parent fc7132c commit b02e9f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
16 changes: 8 additions & 8 deletions src/InternetSearch/Client/QuakeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public List<SearchResultEntry> parseResp(String respbody) {

SearchResultEntry entry = new SearchResultEntry();


entry.getIPSet().add(entryitem.getString("ip"));
entry.setRootDomain(entryitem.getString("domain"));

Expand Down Expand Up @@ -89,7 +88,8 @@ public boolean hasNextPage(String respbody,int currentPage) {
int size = 500;
ArrayList<String> 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;
}
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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);

Expand Down
23 changes: 10 additions & 13 deletions src/Tools/JSONHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -49,11 +45,11 @@ public static boolean isJSONArray(String test) {
}
}

public static ArrayList<String> grepValueFromJson(String jsonString,String toFind) throws Exception {
public static ArrayList<String> grepValueFromJson(String jsonString,String keyName) throws Exception {
ArrayList<String> result = new ArrayList<String>();

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];
}
Expand All @@ -67,24 +63,24 @@ public static ArrayList<String> 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<obj.length();i++) {
String item = obj.get(i).toString();
result.addAll(grepValueFromJson(item,toFind));
result.addAll(grepValueFromJson(item,keyName));
}
}else {
String reg = String.format("\"%s\":[\\s]*[\"]{0,1}(.*?)[\"]{0,1}[,}]+", toFind);
String reg = String.format("\"%s\":[\\s]*[\"]{0,1}(.*?)[\"]{0,1}[,}]+", keyName);

Pattern pDomainNameOnly = Pattern.compile(reg);
Matcher matcher = pDomainNameOnly.matcher(jsonString);
Pattern pattern = Pattern.compile(reg);
Matcher matcher = pattern.matcher(jsonString);
while (matcher.find()) {//多次查找
String item = matcher.group(1);
//System.out.println("111"+item+"111");
Expand All @@ -94,6 +90,7 @@ public static ArrayList<String> grepValueFromJson(String jsonString,String toFin
return result;
}


public static void test() {
String aaa = "[\r\n" +
" {\r\n" +
Expand Down

0 comments on commit b02e9f8

Please sign in to comment.