Explorar el Código

add weixinzhishu: search_key

wangkun hace 2 años
padre
commit
4ab1bf9311

+ 2 - 0
common/publish.py

@@ -230,6 +230,8 @@ class Publish:
             return 'GANGGANGDOUCHUAN'
         elif crawler == 'gongzhonghao_xinxin':
             return 'GONGZHONGHAO_XINXIN'
+        elif crawler == 'weixinzhishu':
+            return 'WEIXINZHISHU'
 
     @classmethod
     def local_file_path(cls, crawler):

+ 16 - 25
weixinzhishu/weixinzhishu_main/search_key.py

@@ -1,6 +1,18 @@
 # -*- coding: utf-8 -*-
 # @Author: wangkun
 # @Time: 2023/2/10
+"""
+获取微信指数小程序请求参数:search_key
+    1. 启动 WinAppDriver.exe
+    2. 启动 Charles.exe:
+        2.1 选中 Proxy - Windows Proxy
+        2.2 选中 Tools - Auto Save - Enable Auto Save
+    3. 启动 Python 脚本:
+        3.1 cd D:\piaoquan_crawler
+        3.2 python .\weixinzhishu\weixinzhishu_main\search_key.py
+每分钟获取最新search_key,写入飞书: https://w42nne6hzg.feishu.cn/sheets/shtcnqhMRUGunIfGnGXMOBYiy4K?sheet=sVL74k
+"""
+
 import json
 import os
 import sys
@@ -17,18 +29,11 @@ class Searchkey:
     def start_wechat(cls, log_type, crawler):
         try:
             # Common.logger(log_type, crawler).info('启动"微信"')
-            # print('启动"微信"')
             desired_caps = {'app': r"C:\Program Files (x86)\Tencent\WeChat\WeChat.exe"}
             driver = webdriver.Remote(
                 command_executor='http://127.0.0.1:4723',
                 desired_capabilities=desired_caps)
             driver.implicitly_wait(10)
-            # Common.logger(log_type).info('点击"聊天窗口"')
-            # driver.find_element(By.NAME, '聊天').click()
-            #
-            # Common.logger(log_type).info('点击"爬虫群"')
-            # driver.find_elements(By.NAME, '爬虫群')[0].click()
-
             # Common.logger(log_type, crawler).info('点击微信指数')
             driver.find_elements(By.NAME, '消息')[-1].click()
             # Common.logger(log_type, crawler).info('休眠 3 秒,退出微信')
@@ -42,26 +47,12 @@ class Searchkey:
         try:
             # charles 抓包文件保存目录
             chlsfile_path = f"./{crawler}/{crawler}_chlsfiles/"
-            # chlsfile_path = f"../weixinzhishu_chlsfiles/"
-            # chlsfile_list = []
             if len(os.listdir(chlsfile_path)) == 0:
                 Common.logger(log_type, crawler).info("chlsfile文件夹为空,等待10s")
                 cls.start_wechat(log_type, crawler)
                 time.sleep(10)
                 cls.get_search_key(log_type, crawler)
-            # else:
-            #     for file in all_file:
-            #         if file.endswith("chlsj") is False:
-            #             os.remove(f"./{crawler}/{crawler}_chlsfiles/{file}")
-            #         else:
-            #             chlsfile_list.append(file)
-            # if len(chlsfile_list) == 0:
-            #     Common.logger(log_type, crawler).info('未找到chlsfile文件,重新获取')
-            #     cls.start_wechat(log_type, crawler)
-            #     time.sleep(10)
-            #     cls.get_search_key(log_type, crawler)
             else:
-                Common.logger(log_type, crawler).info(f"len(chlsfile):{len(os.listdir(chlsfile_path))}")
                 Common.logger(log_type, crawler).info(f"chlsfile_list:{sorted(os.listdir(chlsfile_path))}")
                 # 获取最新的 chlsfile
                 chlsfile = sorted(os.listdir(chlsfile_path))[-1]
@@ -103,7 +94,6 @@ class Searchkey:
     def del_search_key_from_feishu(cls, log_type, crawler):
         try:
             sheet = Feishu.get_values_batch(log_type, crawler, 'sVL74k')
-            # print(len(sheet))
             if len(sheet) <= 21:
                 # print('<=20行')
                 return
@@ -139,6 +129,7 @@ class Searchkey:
 
 
 if __name__ == '__main__':
-    # Searchkey.start_wechat('searchkey', 'weixinzhishu')
-    Searchkey.write_search_key_to_feishu('searchkey', 'weixinzhishu')
-    pass
+    while True:
+        Searchkey.write_search_key_to_feishu('searchkey', 'weixinzhishu')
+        Common.logger('searchkey', 'weixinzhishu').info('休眠 1 分钟')
+        time.sleep(60)

+ 1 - 1
weixinzhishu/weixinzhishu_main/weixinzhishu.py

@@ -11,7 +11,7 @@ class Weixinzhishu:
         url = "https://search.weixin.qq.com/cgi-bin/wxaweb/wxindex"
         payload = json.dumps({
             "openid": "ov4ns0OAM_om-YOT7idMCe5gxoeQ",
-            "search_key": "1676007537546259_3170762354",
+            "search_key": "1676279841643011_944075427",
             "cgi_name": "GetDefaultIndex",
             "start_ymd": "20230206",
             "end_ymd": "20230210",