wangkun 2 lat temu
rodzic
commit
4a8b83b826
3 zmienionych plików z 48 dodań i 73 usunięć
  1. 0 70
      main/click_share_video.py
  2. 39 2
      main/shipinhao_get_url.py
  3. 9 1
      main/shipinhao_recommend.py

+ 0 - 70
main/click_share_video.py

@@ -1,70 +0,0 @@
-# -*- coding: utf-8 -*-
-# @Author: wangkun
-# @Time: 2022/9/1
-import os
-import sys
-import time
-import atomacos
-from appium import webdriver
-from selenium.webdriver.common.by import By
-sys.path.append(os.getcwd())
-from crawler_shipinhao.main.common import Common
-# from main.common import Common
-
-
-class Click:
-    @classmethod
-    def click_video(cls, log_type, video_title):
-        Common.logger(log_type).info('启动"微信"')
-        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('点击视频:{}', video_title)
-        driver.find_element(By.NAME, video_title).click()
-        time.sleep(5)
-        driver.quit()
-
-    @classmethod
-    def click_video_mac(cls, log_type, video_title):
-        bundle_id = "com.tencent.xinWeChat"
-
-        # 启动应用
-        atomacos.launchAppByBundleId(bundle_id)
-        atomator = atomacos.getAppRefByBundleId(bundle_id)
-        time.sleep(3)
-
-        # 获取当前窗口
-        wx = atomator.windows()[0]
-        print(wx)
-
-        # # 获取群:爬虫群
-        # msg_windown = wx.findFirstR(AXRole="AXCell", AXParent="爬虫群")
-        # print(msg_windown)
-        # msg_windown.Press()
-
-        # # 获取位置参数
-        # msg_windown_position = msg_windown.AXPosition
-        # msg_windown_size = msg_windown.AXSize
-        # 注意AXPositon得到的坐标是元素左上角的坐标,需要根据实际大小得到元素中心点坐标
-        # msg_windown_click = (lt_position[0] + lt_size[0] / 2, lt_position[1] + lt_size[1])
-        # print(lt_click)
-        # lt.clickMouseButtonLeft(lt_position)
-        #
-        # # 输入内容(输入键盘字符,US_keyboard)
-        # # s1 = lt.findFirstR(AXRole='AXTextArea', AXRoleDescription='文本输入区')
-        # s1 = lt.findFirstR(AXRole='AXTextArea', AXLable='搜索')
-        # s1_p = s1.AXPosition
-        # s1_s = s1.AXSize
-        # s1.tripleClickMouse((s1_p[0] + s1_s[0] / 2, s1_p[1] + s1_s[1] / 2))
-        # s1.sendKeys('公众号')
-
-
-if __name__ == '__main__':
-    # Click.click_video('recommend', '意外和明天谁都不知道哪个先来,所以请珍惜眼前人吧!特别是自己的家的男人在工地上干活的!那个条件,还有高危险作业的人们,谁都不是很努力的活着呀…')
-    Click.click_video_mac('recommend', '国家卫健委:昨日新增本土确诊病例307例!')

+ 39 - 2
main/get_url.py → main/shipinhao_get_url.py

@@ -5,12 +5,33 @@ import json
 import os
 import sys
 import time
+# import atomacos
+from appium import webdriver
+from selenium.webdriver.common.by import By
 sys.path.append(os.getcwd())
 from crawler_shipinhao.main.common import Common
+from crawler_shipinhao.main.feishu_lib import Feishu
 # from main.common import Common
 
 
 class GetUrl:
+    @classmethod
+    def click_video(cls, log_type, video_title):
+        Common.logger(log_type).info('启动"微信"')
+        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('点击视频:{}', video_title)
+        driver.find_element(By.NAME, video_title).click()
+        time.sleep(5)
+        driver.quit()
+
     @classmethod
     def get_url(cls, log_type):
         try:
@@ -45,13 +66,14 @@ class GetUrl:
                     for text in contents:
                         if text["host"] == "finder.video.qq.com" and text["path"] == "/251/20302/stodownload":
                             video_url_list.append(text)
-                        elif text["host"] == "finder.video.qq.com" and text["path"] == "/251/20350/stodownload":
+                        elif text["host"] == "finder.video.qq.com" and text["path"] == "/251/20304/stodownload":
                             cover_url_list.append(text)
 
                     video_url = video_url_list[0]['host']+video_url_list[0]['path']+'?'+video_url_list[0]['query']
                     cover_url = cover_url_list[0]['host']+cover_url_list[0]['path']+'?'+cover_url_list[0]['query']
+                    head_url = cover_url
 
-                    return video_url, cover_url
+                    return video_url, cover_url, head_url
                 else:
                     Common.logger(log_type).info("未找到 url,10s后重新获取")
                     time.sleep(10)
@@ -61,6 +83,21 @@ class GetUrl:
             Common.logger(log_type).exception("get_url异常:{}", e)
             return None
 
+    @classmethod
+    def write_url(cls, log_type):
+        while True:
+            if Feishu.get_values_batch(log_type, 'shipinhao', 'FSDlBy')[1][11] is None:
+                Common.logger(log_type).info('开始点击分享的视频')
+                cls.click_video(log_type, Feishu.get_values_batch(log_type, 'shipinhao', 'FSDlBy')[1][2])
+                time.sleep(60)
+                Common.logger(log_type).info('获取视频头像/封面/播放地址')
+                urls = cls.get_url(log_type)
+                Feishu.update_values(log_type, 'shipinhao', '', 'J2:L2', [[urls[2], urls[1], urls[0]]])
+                Common.logger(log_type).info('视频地址信息写入飞书成功\n')
+                break
+            else:
+                break
+
 
 if __name__ == '__main__':
     GetUrl.get_url('recommend')

+ 9 - 1
main/shipinhao_recommend.py

@@ -94,7 +94,7 @@ class Recommend:
     def get_feeds(cls, log_type, driver: WebDriver):
         try:
             driver.implicitly_wait(10)
-            for i in range(10):
+            for i in range(5):
                 # # 关闭页面弹窗
                 # try:
                 #     driver.find_element(By.XPATH, '//*[@text="我知道了"]').click()
@@ -249,11 +249,19 @@ class Recommend:
                     Common.logger(log_type).info('向上滑动页面')
                     driver.swipe(500, 1500, 500, 500, 300)
                     Common.logger(log_type).info('视频信息写入飞书文档成功\n')
+
+                    while True:
+                        if Feishu.get_values_batch(log_type, 'shipinhao', 'FSDlBy')[1][11] is None:
+                            time.sleep(1)
+                        else:
+                            break
         except Exception as e:
             Common.logger(log_type).error('get_feeds异常', e)
+            driver.swipe(500, 1500, 500, 500, 300)
 
 
 if __name__ == '__main__':
     Recommend.start_wechat('recommend')
+    # print(Feishu.get_values_batch('log_type', 'shipinhao', 'FSDlBy')[1][11])
 
     pass