add - bili90
This commit is contained in:
@@ -46,7 +46,7 @@ public class PushAgent extends Spider {
|
||||
@Override
|
||||
public void init(Context context, String extend) {
|
||||
super.init(context, extend);
|
||||
fetchRule(false,0);
|
||||
if(extend!=null&&!extend.equals("")) getToken(Token);
|
||||
}
|
||||
|
||||
public void getToken(String token){
|
||||
|
||||
@@ -244,31 +244,17 @@ public class Misc {
|
||||
|
||||
public static ArrayList<String> subContent(String content, String startFlag, String endFlag) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
if (startFlag.isEmpty() && endFlag.isEmpty()) {
|
||||
result.add(content);
|
||||
return result;
|
||||
}
|
||||
try {
|
||||
Pattern pattern = Pattern.compile(escapeExprSpecialWord(startFlag) + "(.*?)" + escapeExprSpecialWord(endFlag));
|
||||
Matcher matcher = pattern.matcher(content);
|
||||
while (matcher.find()) {
|
||||
result.add(matcher.group(1));
|
||||
if (content != null && content.length() > 1) {
|
||||
try {
|
||||
Pattern pattern = Pattern.compile(startFlag + "(.*?)" + endFlag);
|
||||
Matcher matcher = pattern.matcher(content);
|
||||
while (matcher.find()) {
|
||||
result.add(matcher.group(1));
|
||||
}
|
||||
} catch (Throwable th) {
|
||||
th.printStackTrace();
|
||||
}
|
||||
} catch (Throwable th) {
|
||||
th.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String escapeExprSpecialWord(String regexStr) {
|
||||
if (!regexStr.isEmpty()) {
|
||||
String[] fbsArr = {"\\", "$", "(", ")", "*", "+", ".", "[", "]", "?", "^", "{", "}", "|"};
|
||||
for (String key : fbsArr) {
|
||||
if (regexStr.contains(key)) {
|
||||
regexStr = regexStr.replace(key, "\\" + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
return regexStr;
|
||||
}
|
||||
}
|
||||
@@ -3,16 +3,11 @@ package com.github.catvod.utils.okhttp;
|
||||
import com.github.catvod.crawler.SpiderDebug;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Cookie;
|
||||
import okhttp3.CookieJar;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Response;
|
||||
|
||||
@@ -21,7 +16,7 @@ public class OkHttpUtil {
|
||||
public static final String METHOD_GET = "GET";
|
||||
public static final String METHOD_POST = "POST";
|
||||
|
||||
private static final int DEFAULT_TIMEOUT = 15;
|
||||
public static final int DEFAULT_TIMEOUT = 20;
|
||||
|
||||
private static final Object lockO = new Object();
|
||||
|
||||
@@ -32,24 +27,10 @@ public class OkHttpUtil {
|
||||
*/
|
||||
private static OkHttpClient noRedirectClient = null;
|
||||
|
||||
public static HashMap<String, List<Cookie>> cookieStore = new HashMap<>();
|
||||
|
||||
public static OkHttpClient defaultClient() {
|
||||
synchronized (lockO) {
|
||||
if (defaultClient == null) {
|
||||
OkHttpClient.Builder builder = new OkHttpClient.Builder()
|
||||
.cookieJar(new CookieJar() {
|
||||
@Override
|
||||
public void saveFromResponse(HttpUrl httpUrl, List<Cookie> list) {
|
||||
cookieStore.put(httpUrl.host(), list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Cookie> loadForRequest(HttpUrl httpUrl) {
|
||||
List<Cookie> cookies = cookieStore.get(httpUrl.host());
|
||||
return cookies != null ? cookies : new ArrayList<>();
|
||||
}
|
||||
})
|
||||
.readTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
|
||||
.writeTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
|
||||
.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
|
||||
|
||||
Reference in New Issue
Block a user