wangkun 2 vuotta sitten
vanhempi
commit
4c5680fa16
2 muutettua tiedostoa jossa 29 lisäystä ja 21 poistoa
  1. 1 1
      main/run_zhiqingzongqun_recommend.py
  2. 28 20
      main/zhiqingzongqun_recommend.py

+ 1 - 1
main/run_zhiqingzongqun_recommend.py

@@ -13,8 +13,8 @@ class Main:
     @classmethod
     def main(cls, log_type, env):
         while True:
-            if 23 >= datetime.datetime.now().hour >= 17:
             # if datetime.datetime.now().hour >= 0:
+            if 23 >= datetime.datetime.now().hour >= 17:
                 Common.logger(log_type).info('开始抓取知青总群\n')
                 Recommend.start_wechat(log_type, env)
                 Recommend.i = 0

+ 28 - 20
main/zhiqingzongqun_recommend.py

@@ -219,25 +219,7 @@ class Recommend:
                         elif '精美图文' in video_title:
                             video_url = 0
                         else:
-                            Common.logger(log_type).info('进入视频详情:{}', video_title)
-                            title.click()
-                            time.sleep(5)
-                            Common.logger(log_type).info('关闭广告')
-                            size = driver.get_window_size()
-                            TouchAction(driver).tap(x=int(size['width'] * 0.5), y=int(size['height'] * 0.1)).perform()
-                            time.sleep(10)
-                            info_handles = driver.window_handles
-                            for info_handle in info_handles:
-                                try:
-                                    driver.switch_to.window(info_handle)
-                                    url = driver.find_element(
-                                        By.XPATH,
-                                        '//*[@class="wx-swiper-slide-frame"]'
-                                        '/*[2]//*[@class="video_item videoswiper--video_item"]')
-                                    video_url = url.get_attribute('src')
-                                    break
-                                except NoSuchElementException:
-                                    pass
+                            video_url = cls.get_url(log_type, driver, video_title, title)
 
                         Common.logger(log_type).info('video_title:{}', video_title)
                         Common.logger(log_type).info('play_cnt:{}', play_cnt)
@@ -248,7 +230,8 @@ class Recommend:
                         elif '精美图文' in video_title:
                             Common.logger(log_type).info('精美图文\n')
                         elif any(word if word in video_title else False for word in cls.filter_words(log_type)) is True:
-                            Common.logger(log_type).info('视频已中过滤词:{}', video_title)
+                            Common.logger(log_type).info('视频已中过滤词:{}\n', video_title)
+                            driver.press_keycode(4)
                         elif video_title in [x for y in Feishu.get_values_batch(
                                 log_type, 'zhiqingzongqun', 'Z48hlq') for x in y]:
                             Common.logger(log_type).info('视频已存在\n')
@@ -285,6 +268,31 @@ class Recommend:
             cls.quit(log_type, driver)
             cls.start_wechat(log_type, env)
 
+    @classmethod
+    def get_url(cls, log_type, driver: WebDriver, video_title, title):
+        try:
+            Common.logger(log_type).info('进入视频详情:{}', video_title)
+            title.click()
+            time.sleep(5)
+            Common.logger(log_type).info('关闭广告')
+            size = driver.get_window_size()
+            TouchAction(driver).tap(x=int(size['width'] * 0.5), y=int(size['height'] * 0.1)).perform()
+            time.sleep(10)
+            info_handles = driver.window_handles
+            for info_handle in info_handles:
+                try:
+                    driver.switch_to.window(info_handle)
+                    url = driver.find_element(
+                        By.XPATH,
+                        '//*[@class="wx-swiper-slide-frame"]'
+                        '/*[2]//*[@class="video_item videoswiper--video_item"]')
+                    video_url = url.get_attribute('src')
+                    return video_url
+                except NoSuchElementException:
+                    pass
+        except Exception as e:
+            Common.logger(log_type).error('get_url异常:{}\n', e)
+
     @classmethod
     def download_publish(cls, log_type, env):
         try: