瀏覽代碼

脚本修复

dzr 2 周之前
父節點
當前提交
b826af5642

+ 44 - 0
hb_hbzwfww_bacx_njpc/utils.py

@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+"""
+Created on 2025-07-16 
+---------
+@summary:  
+---------
+@author: Dzr
+"""
+
+import math
+import random
+import string
+import time
+
+
+def hex36(num: int) -> str:
+    if num == 0:
+        return '0'
+
+    alphabet = string.digits + string.ascii_lowercase
+    base36 = ''
+    while num:
+        num, i = divmod(num, 36)
+        base36 = alphabet[i] + base36
+    return base36
+
+
+def token():
+    """36进制字符串"""
+    '''
+        function token() {
+            var Ie = 911
+                , Pe = 20170706
+                , Fe = 1e9;
+            extoken = (n = Math.floor(10 * Math.random()) * Fe,
+                (((new Date).getTime() % Fe + n) * Ie + Pe).toString(36))
+            return extoken
+        }
+    '''
+    ie = 911
+    pe = 20170706
+    fe = 10 ** 9  # 1e9
+    n = math.floor(10 * random.random()) * fe
+    return hex36((int(time.time() * 1000) % fe + n) * ie + pe)

+ 8 - 22
hb_hbzwfww_bacx_njpc/湖北政务服务网-备案查询-列表页.py

@@ -9,27 +9,13 @@ Created on 2025-02-15
 import json
 from collections import namedtuple
 
-import execjs
 import feapder
 from items.njpc_item import NjpcListItem
 
+from utils import token as get_token
 
-def get_token():
-    ex_js = '''
-    function token() {
-        var Ie = 911
-            , Pe = 20170706
-            , Fe = 1e9;
-        extoken = (n = Math.floor(10 * Math.random()) * Fe,
-            (((new Date).getTime() % Fe + n) * Ie + Pe).toString(36))
-        return extoken
-    }
-    '''
-    ctx = execjs.compile(ex_js)
-    return ctx.call('token')
 
-
-class NjpcSpider(feapder.PlanToBuildListSpider):
+class Spider(feapder.PlanToBuildListSpider):
 
     def start_callback(self):
         Menu = namedtuple('Menu', ['channel', 'code', 'crawl_page'])
@@ -101,9 +87,10 @@ class NjpcSpider(feapder.PlanToBuildListSpider):
         info_list = response.json.get('data').get('list')
         for info in info_list:
             approvecode = info.get('project_code') or info.get('_id')
-            detail_href = "https://tzxm.hubei.gov.cn/xxgk?" + approvecode
             projectname = info.get('project_name').strip()
             publish_time = info.get('declaration_date').strip()
+            url = "/".join(["https://tzxm.hubei.gov.cn/xxgk", publish_time, approvecode])
+            detail_href = f"{url}?q={menu['channel']}"
             owner = info.get('unit_name')
 
             area = "湖北"    # 省份
@@ -125,14 +112,13 @@ class NjpcSpider(feapder.PlanToBuildListSpider):
             data_item.district = district  # 城市 默认为空
             data_item.parser_url = "https://tzxm.hubei.gov.cn:7216/api/proxy/custom/hb/hb_aiapp/xMod/filing_search/customShow"
             data_item.href = detail_href  # 详情链接
-            ddata = {
+            json_str = json.dumps({
                 "_id": info.get('_id'),
                 "switchLoginRequired": "off",
                 "screenKey": "SCR_l4xunf59n2"
-            }
-            ddata = json.dumps(ddata)
+            })
             data_item.request_params = {
-                "data": ddata,
+                "data": json_str,
                 "method": "POST"
             }
             data_item.parser = "detail_get"
@@ -143,4 +129,4 @@ class NjpcSpider(feapder.PlanToBuildListSpider):
 
 
 if __name__ == "__main__":
-    NjpcSpider(redis_key="lzz:hbzwfww_bacx").start()
+    Spider(redis_key="lzz:hbzwfww_bacx").start()

+ 3 - 18
hb_hbzwfww_bacx_njpc/湖北政务服务网-备案查询-详情页.py

@@ -6,29 +6,14 @@ Created on 2024-03-15
 ---------
 @author: lzz
 """
-import execjs
 import feapder
 from items.njpc_item import DataNjpcItem
 
 from hbzwfww_area_dict import area_dict
+from utils import token as get_token
 
 
-def get_token():
-    ex_js = '''
-    function token() {
-        var Ie = 911
-            , Pe = 20170706
-            , Fe = 1e9;
-        extoken = (n = Math.floor(10 * Math.random()) * Fe,
-            (((new Date).getTime() % Fe + n) * Ie + Pe).toString(36))
-        return extoken
-    }
-    '''
-    ctx = execjs.compile(ex_js)
-    return ctx.call('token')
-
-
-class Details(feapder.PlanToBuildDetailSpider):
+class Spider(feapder.PlanToBuildDetailSpider):
 
     def start_requests(self):
         data_list = self.get_tasks_by_rabbitmq(limit=50)
@@ -176,4 +161,4 @@ class Details(feapder.PlanToBuildDetailSpider):
 
 
 if __name__ == '__main__':
-    Details(redis_key="lzz:hbzwfww_bacx").start()
+    Spider(redis_key="lzz:hbzwfww_bacx").start()