Commit eec30e53 by zhiwei

将转临时链接的重试修改带外部,有调用jar的人实现

parent cedeeab7
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.zhiwei</groupId> <groupId>com.zhiwei</groupId>
<artifactId>wechat</artifactId> <artifactId>wechat</artifactId>
<version>1.2.8-SNAPSHOT</version> <version>1.2.9-SNAPSHOT</version>
<description> <description>
知微微信采集程序,包含 知微微信采集程序,包含
1.微信历史文章采集 1.微信历史文章采集
......
...@@ -38,12 +38,9 @@ public class WechatReal { ...@@ -38,12 +38,9 @@ public class WechatReal {
return realUrl; return realUrl;
} }
/**
* 获取真实链接
* @param originalUrl
* @return
* @throws Exception
*/
private static String getFinalUrl(String originalUrl, Proxy proxy) throws Exception{ private static String getFinalUrl(String originalUrl, Proxy proxy) throws Exception{
Map<String,String> headerMap = new HashMap<>(); Map<String,String> headerMap = new HashMap<>();
headerMap.put("Sec-Fetch-Mode", "navigate"); headerMap.put("Sec-Fetch-Mode", "navigate");
...@@ -55,30 +52,22 @@ public class WechatReal { ...@@ -55,30 +52,22 @@ public class WechatReal {
String word = originalUrl.split("query=")[1]; String word = originalUrl.split("query=")[1];
String searchUrl = "https://weixin.sogou.com/weixin?query="+ word; String searchUrl = "https://weixin.sogou.com/weixin?query="+ word;
for(int i=0; i<3; i++){ headerMap.put("referer", searchUrl);
try{ httpBoot.syncCall(RequestUtils.wrapGet(searchUrl, headerMap), proxy).body().string();
headerMap.put("referer", searchUrl);
httpBoot.syncCall(RequestUtils.wrapGet(searchUrl, headerMap), proxy).body().string();
String htmlBody = httpBoot.syncCall(RequestUtils.wrapGet(originalUrl, headerMap), proxy).body().string(); String htmlBody = httpBoot.syncCall(RequestUtils.wrapGet(originalUrl, headerMap), proxy).body().string();
headerMap.put("referer", searchUrl); headerMap.put("referer", searchUrl);
if(StringUtils.isNotBlank(htmlBody) && !htmlBody.contains("验证码")){
if(StringUtils.isNotBlank(htmlBody) && !htmlBody.contains("验证码")){ StringBuilder furl = new StringBuilder();
StringBuilder furl = new StringBuilder(); Pattern pa1 = Pattern.compile("url \\+= \'(.*?)\';");
Pattern pa1 = Pattern.compile("url \\+= \'(.*?)\';"); Matcher ma1 = pa1.matcher(htmlBody);
Matcher ma1 = pa1.matcher(htmlBody); while (ma1.find()) {
while (ma1.find()) { furl.append(ma1.group(1));
furl.append(ma1.group(1));
}
return furl.toString();
}
}catch (Exception e){
if(i==2){
throw e;
}
continue;
} }
return furl.toString();
}else{
throw new NullPointerException("获取临时链接失败");
} }
return null;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment