wangkun 2 years ago
parent
commit
b246b4cdd2
2 changed files with 21 additions and 54 deletions
  1. 13 43
      main/shipinhao_recommend.py
  2. 8 11
      main/shipinhao_topic.py

+ 13 - 43
main/shipinhao_recommend.py

@@ -88,20 +88,6 @@ class Recommend:
         try:
             driver.implicitly_wait(10)
             for i in range(5):
-                # # 关闭页面弹窗
-                # try:
-                #     driver.find_element(By.XPATH, '//*[@text="我知道了"]').click()
-                #     driver.find_element(By.XPATH, '//*[@text="知道了"]').click()
-                #     Common.logger(log_type).info('已关闭未成年模式弹窗')
-                # except NoSuchElementException:
-                #     pass
-                #
-                # try:
-                #     driver.find_element(By.ID, 'com.tencent.mm:id/dkf')
-                #     Common.logger(log_type).info('直播视频,向上滑动页面\n')
-                #     driver.swipe(500, 1500, 500, 500, 300)
-                # except NoSuchElementException:
-                #     pass
 
                 # 视频标题
                 try:
@@ -109,7 +95,7 @@ class Recommend:
                     video_title = title_id.get_attribute('name').split('\n')[0].replace('#', '').strip()
                 except NoSuchElementException:
                     video_title = ''
-                    driver.swipe(500, 1500, 500, 500, 300)
+                    driver.swipe(10, 1600, 10, 300, 200)
 
                 # 点击播放器,获取视频时长
                 # Common.logger(log_type).info('暂停播放')
@@ -186,27 +172,23 @@ class Recommend:
 
                 # 判断无效视频
                 if video_title == '' or user_name == '':
-                    Common.logger(log_type).info('向上滑动页面')
-                    driver.swipe(500, 1500, 500, 500, 300)
-                    Common.logger(log_type).info('无效视频\n')
+                    Common.logger(log_type).info('无效视频,滑动到下一个视频\n')
+                    driver.swipe(10, 1600, 10, 300, 200)
 
                 # 判断下载规则
                 elif cls.download_rule(duration, like_cnt, share_cnt, favorite_cnt, comment_cnt) is False:
-                    Common.logger(log_type).info('向上滑动页面')
-                    driver.swipe(500, 1500, 500, 500, 300)
-                    Common.logger(log_type).info('不满足抓取规则\n')
+                    Common.logger(log_type).info('不满足抓取规则,滑动到下一个视频\n')
+                    driver.swipe(10, 1600, 10, 300, 200)
 
                 # 已下载表去重
                 elif str(video_title) in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'c77cf9') for x in y]:
-                    Common.logger(log_type).info('向上滑动页面')
-                    driver.swipe(500, 1500, 500, 500, 300)
-                    Common.logger(log_type).info('视频已下载\n')
+                    Common.logger(log_type).info('视频已下载,滑动到下一个视频\n')
+                    driver.swipe(10, 1600, 10, 300, 200)
 
                 # feeds 表去重
                 elif str(video_title) in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'FSDlBy') for x in y]:
-                    Common.logger(log_type).info('向上滑动页面')
-                    driver.swipe(500, 1500, 500, 500, 300)
-                    Common.logger(log_type).info('视频已存在\n')
+                    Common.logger(log_type).info('视频已存在,滑动到下一个视频\n')
+                    driver.swipe(10, 1600, 10, 300, 200)
 
                 # 分享给 windows 爬虫机
                 else:
@@ -215,16 +197,6 @@ class Recommend:
                     driver.find_element(By.XPATH, '//*[@text="爬虫群"]').click()
                     driver.find_element(By.ID, 'com.tencent.mm:id/guw').click()
 
-                    # Click.click_video(log_type, video_title)
-                    # time.sleep(1)
-
-                    # urls = GetUrl.get_url(log_type)
-                    # if urls is None:
-                    #     Common.logger(log_type).info('未获取到视频 URL')
-                    # else:
-                    #     video_url = urls[0]
-                    #     cover_url = urls[1]
-
                     # 把视频信息写入飞书feeds文档
                     Feishu.insert_columns(log_type, 'shipinhao', 'FSDlBy', 'ROWS', 1, 2)
                     get_feeds_time = int(time.time())
@@ -239,8 +211,6 @@ class Recommend:
                                str(user_name)]]
                     time.sleep(1)
                     Feishu.update_values(log_type, 'shipinhao', 'FSDlBy', 'A2:Z2', values)
-                    Common.logger(log_type).info('向上滑动页面')
-                    # driver.swipe(500, 1500, 500, 500, 300)
                     Common.logger(log_type).info('视频信息写入飞书文档成功\n')
 
                     while True:
@@ -248,12 +218,12 @@ class Recommend:
                             Common.logger(log_type).info('等待更新 URL 信息')
                             time.sleep(10)
                         else:
-                            Common.logger(log_type).info('URL 信息已更新\n')
-                            driver.swipe(500, 1500, 500, 500, 300)
+                            Common.logger(log_type).info('URL 信息已更新,滑动到下一个视频\n')
+                            driver.swipe(10, 1600, 10, 300, 200)
                             break
         except Exception as e:
-            Common.logger(log_type).error('get_feeds异常\n', e)
-            driver.swipe(500, 1500, 500, 500, 300)
+            Common.logger(log_type).error('get_feeds异常,滑动到下一个视频\n', e)
+            driver.swipe(10, 1600, 10, 300, 200)
 
     # 下载 、上传
     @classmethod

+ 8 - 11
main/shipinhao_topic.py

@@ -111,7 +111,7 @@ class Topic:
 
     # 操作安卓手机,自己滑动首页视频,并获取视频信息
     @classmethod
-    def get_feeds(cls, log_type, driver: WebDriver):
+    def get_feeds(cls, log_type, topic, driver: WebDriver):
         try:
             driver.implicitly_wait(10)
             while True:
@@ -208,9 +208,8 @@ class Topic:
 
                 # 判断无效视频
                 if video_title == '' or user_name == '':
-                    Common.logger(log_type).info('向上滑动页面')
+                    Common.logger(log_type).info('无效视频,滑动到下一个视频\n')
                     driver.swipe(10, 1600, 10, 300, 200)
-                    Common.logger(log_type).info('无效视频\n')
 
                 # 判断下载规则
                 elif cls.download_rule(duration, like_cnt, share_cnt, favorite_cnt, comment_cnt) is False:
@@ -220,16 +219,14 @@ class Topic:
                 # 已下载表去重
                 elif str(video_title) in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'c77cf9') for x
                                           in y]:
-                    Common.logger(log_type).info('向上滑动页面')
+                    Common.logger(log_type).info('视频已下载,滑动到下一个视频\n')
                     driver.swipe(10, 1600, 10, 300, 200)
-                    Common.logger(log_type).info('视频已下载\n')
 
                 # feeds 表去重
                 elif str(video_title) in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'FSDlBy') for x
                                           in y]:
-                    Common.logger(log_type).info('向上滑动页面')
+                    Common.logger(log_type).info('视频已存在,滑动到下一个视频\n')
                     driver.swipe(10, 1600, 10, 300, 200)
-                    Common.logger(log_type).info('视频已存在\n')
 
                 # 分享给 windows 爬虫机
                 else:
@@ -242,7 +239,7 @@ class Topic:
                     Feishu.insert_columns(log_type, 'shipinhao', 'FSDlBy', 'ROWS', 1, 2)
                     get_feeds_time = int(time.time())
                     values = [[time.strftime('%Y/%m/%d %H:%M:%S', time.localtime(get_feeds_time)),
-                               '话题榜',
+                               '话题榜:'+str(topic),
                                str(video_title),
                                duration,
                                like_cnt,
@@ -259,7 +256,7 @@ class Topic:
                             Common.logger(log_type).info('等待更新 URL 信息')
                             time.sleep(10)
                         else:
-                            Common.logger(log_type).info('URL 信息已更新\n')
+                            Common.logger(log_type).info('URL 信息已更新,滑动到下一个视频\n')
                             cls.video_cnt.append(video_title)
                             driver.swipe(10, 1600, 10, 300, 200)
                             break
@@ -272,7 +269,7 @@ class Topic:
                         return
 
         except Exception as e:
-            Common.logger(log_type).error('get_feeds异常\n', e)
+            Common.logger(log_type).error('get_feeds异常,滑动到下一个视频\n', e)
             driver.swipe(10, 1600, 10, 300, 200)
 
     @classmethod
@@ -310,7 +307,7 @@ class Topic:
                     driver.switch_to.context('NATIVE_APP')
 
                     time.sleep(3)
-                    cls.get_feeds(log_type, driver)
+                    cls.get_feeds(log_type, topic, driver)
                     return
 
         except Exception as e: