add - bili90
This commit is contained in:
@@ -46,7 +46,7 @@ public class PushAgent extends Spider {
|
|||||||
@Override
|
@Override
|
||||||
public void init(Context context, String extend) {
|
public void init(Context context, String extend) {
|
||||||
super.init(context, extend);
|
super.init(context, extend);
|
||||||
fetchRule(false,0);
|
if(extend!=null&&!extend.equals("")) getToken(Token);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getToken(String token){
|
public void getToken(String token){
|
||||||
|
|||||||
@@ -244,31 +244,17 @@ public class Misc {
|
|||||||
|
|
||||||
public static ArrayList<String> subContent(String content, String startFlag, String endFlag) {
|
public static ArrayList<String> subContent(String content, String startFlag, String endFlag) {
|
||||||
ArrayList<String> result = new ArrayList<>();
|
ArrayList<String> result = new ArrayList<>();
|
||||||
if (startFlag.isEmpty() && endFlag.isEmpty()) {
|
if (content != null && content.length() > 1) {
|
||||||
result.add(content);
|
try {
|
||||||
return result;
|
Pattern pattern = Pattern.compile(startFlag + "(.*?)" + endFlag);
|
||||||
}
|
Matcher matcher = pattern.matcher(content);
|
||||||
try {
|
while (matcher.find()) {
|
||||||
Pattern pattern = Pattern.compile(escapeExprSpecialWord(startFlag) + "(.*?)" + escapeExprSpecialWord(endFlag));
|
result.add(matcher.group(1));
|
||||||
Matcher matcher = pattern.matcher(content);
|
}
|
||||||
while (matcher.find()) {
|
} catch (Throwable th) {
|
||||||
result.add(matcher.group(1));
|
th.printStackTrace();
|
||||||
}
|
}
|
||||||
} catch (Throwable th) {
|
|
||||||
th.printStackTrace();
|
|
||||||
}
|
}
|
||||||
return result;
|
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 com.github.catvod.crawler.SpiderDebug;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import okhttp3.Call;
|
import okhttp3.Call;
|
||||||
import okhttp3.Cookie;
|
|
||||||
import okhttp3.CookieJar;
|
|
||||||
import okhttp3.HttpUrl;
|
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
|
|
||||||
@@ -21,7 +16,7 @@ public class OkHttpUtil {
|
|||||||
public static final String METHOD_GET = "GET";
|
public static final String METHOD_GET = "GET";
|
||||||
public static final String METHOD_POST = "POST";
|
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();
|
private static final Object lockO = new Object();
|
||||||
|
|
||||||
@@ -32,24 +27,10 @@ public class OkHttpUtil {
|
|||||||
*/
|
*/
|
||||||
private static OkHttpClient noRedirectClient = null;
|
private static OkHttpClient noRedirectClient = null;
|
||||||
|
|
||||||
public static HashMap<String, List<Cookie>> cookieStore = new HashMap<>();
|
|
||||||
|
|
||||||
public static OkHttpClient defaultClient() {
|
public static OkHttpClient defaultClient() {
|
||||||
synchronized (lockO) {
|
synchronized (lockO) {
|
||||||
if (defaultClient == null) {
|
if (defaultClient == null) {
|
||||||
OkHttpClient.Builder builder = new OkHttpClient.Builder()
|
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)
|
.readTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
|
||||||
.writeTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
|
.writeTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
|
||||||
.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
|
.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
|
||||||
@@ -183,7 +164,7 @@ public class OkHttpUtil {
|
|||||||
public static void cancel(Object tag) {
|
public static void cancel(Object tag) {
|
||||||
cancel(defaultClient(), tag);
|
cancel(defaultClient(), tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void cancelAll() {
|
public static void cancelAll() {
|
||||||
cancelAll(defaultClient());
|
cancelAll(defaultClient());
|
||||||
}
|
}
|
||||||
@@ -216,4 +197,4 @@ public class OkHttpUtil {
|
|||||||
return headers.get("Location").get(0);
|
return headers.get("Location").get(0);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user