Bladeren bron

增加验证

huoshengxu 2 jaren geleden
bovenliggende
commit
210b0bf309

+ 14 - 5
src/main/java/com/mingxue/spider/utils/HttpUtils.java

@@ -36,7 +36,7 @@ import com.alibaba.fastjson.JSON;
 
 /**
  * 通用http发送方法
- * 
+ *
  * @author ruoyi
  */
 public class HttpUtils {
@@ -54,6 +54,16 @@ public class HttpUtils {
                 httpPost.setHeader("u-token", accessToken);
             }
             httpPost.setHeader("Content-Type", "application/json");
+            httpPost.setHeader("Accept", "*/*");
+            httpPost.setHeader("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8");
+            httpPost.setHeader("Connection", "keep-alive");
+            httpPost.setHeader("Origin", "https://pv4y-pc.youzy.cn");
+            httpPost.setHeader("Referer", "https://pv4y-pc.youzy.cn");
+            httpPost.setHeader("Sec-Fetch-Dest", "empty");
+            httpPost.setHeader("Sec-Fetch-Mode", "cors");
+            httpPost.setHeader("Sec-Fetch-Site", "same-site");
+            httpPost.setHeader("Accept", "*");
+            httpPost.setHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36");
             CloseableHttpResponse response = httpClient.execute(httpPost);
             String result = "";
             int statusCode = response.getStatusLine().getStatusCode();
@@ -64,7 +74,7 @@ public class HttpUtils {
                     result = EntityUtils.toString(httpEntity);
                 }
             }else {
-                
+
             }
             return result;
         } catch (Exception e) {
@@ -73,7 +83,6 @@ public class HttpUtils {
         }
         return "";
     }
-
     public static String postBody(String postUrl, String body, String uSign) {
         return postBody(postUrl, body, uSign, null);
     }
@@ -83,7 +92,7 @@ public class HttpUtils {
     }
 
     /**
-     * 
+     *
      * @param url
      * @param param
      * @return
@@ -292,4 +301,4 @@ public class HttpUtils {
         }
         return def;
     }
-}
+}

+ 2 - 2
src/main/java/com/mingxue/spider/youzy/ChooseSubjectService.java

@@ -60,7 +60,7 @@ public class ChooseSubjectService extends AbstractService {
 
         String excludeProvinceName = "河北";
         if(excludeProvinceName.equalsIgnoreCase(provinceName)){
-            pageIndex = 33;//甘肃:开始1-17页
+//            pageIndex = 33;//甘肃:开始1-17页
         }
         while (true) {
             try {
@@ -72,7 +72,7 @@ public class ChooseSubjectService extends AbstractService {
                 body.set("collegeKeywords", Collections.EMPTY_LIST).set("provinceCodes", Collections.EMPTY_LIST);
                 body.set("collegeCodes", Collections.EMPTY_LIST).set("features", Collections.EMPTY_LIST);
                 body.set("natures", Collections.EMPTY_LIST).set("categories", Collections.EMPTY_LIST);
-                body.set("provinceCode", provinceCode).set("year", year);
+                body.set("provinceCode", Integer.parseInt(provinceCode)).set("year", year);
                 JSONObject res = (JSONObject)postBody(api, null, body);
                 JSONArray arr = res.getJSONArray("items");
                 if (null == arr || arr.size() == 0) {

File diff suppressed because it is too large
+ 50 - 0
src/test/java/spider/CollegeData2.java


Some files were not shown because too many files changed in this diff