wangkun 2 éve
szülő
commit
e43a143963

BIN
.DS_Store


+ 38 - 183
main/demo.py

@@ -1,14 +1,17 @@
 # @Author: wangkun
 # @Time: 2月 25, 2022
-import datetime
+import difflib
 import logging
 import os
 import sys
 import time
+
+from selenium.webdriver import DesiredCapabilities
+from selenium.webdriver.common.by import By
+from seleniumwire import webdriver
+
 sys.path.append(os.getcwd())
 from main.feishu_lib import Feishu
-from main.publish import Publish
-from main.common import Common
 path = "../videoinfo/"
 
 
@@ -21,186 +24,6 @@ class Demo:
             name = content
             return name
 
-    @classmethod
-    def write_videoname(cls):
-        n = int(float(cls.read_videoname()))
-        with open(path + "videoname.txt", "w", encoding="utf8") as f:
-            f.write(str(n + 1))
-
-    @classmethod
-    def split_text(cls):
-        path1 = "./chlsfiles/"
-        files = os.listdir(path1)
-        for file in files:
-            print(file)
-            print("\n==========\n")
-            a = os.path.splitext(file)
-            print(a[-1])
-
-            # print(file[0])
-            # print(file[-1])
-
-    @classmethod
-    def split_query(cls):
-        url = "encfilekey=Cvvj5Ix3eez3Y79SxtvVL0L7CkPM6dFibFeI6caGYwFHPibicjZB7UrwpKsG9wQrl01" \
-              "IlTMtIjicibib9iaGoaL2sxR7vGt4sofODkBGnic9EOCZjgCQTlO7ZTNjribxkDmPq40E2RMdXxzGlWDwYfmkWz4Q15g" \
-              "&token=AxricY7RBHdVbVKZOkvCOWwYWwj9zBqet1eia6GZib8GhmdrytdBu5HcPARtxW7l0AAzppsekDUXXQ&idx=1&adap" \
-              "tivelytrans=943&bizid=1023&dotrans=2991&hy=SH&m=d04052b0ab0e3dd64567fa60b16d0898&scene=0&t=1&taskid=0"
-        a = url.split("encfilekey=")[-1].split("&token=")[0]
-        print(a)
-
-    @classmethod
-    def distent(cls):
-        filekey = "Cvvj5Ix3eez3Y79SxtvVL0L7CkPM6dFibFeI6caGYwFEiaKINib2TA0ibV5JuXfIA5JysRWeytU3kTufCr7KFPLgwMiauCic" \
-                  "UypoEbA31w7w3sibnraPEwcMcG6LqxSmdFN5S8AfhuibFicv86oBfSuSXcibrCqw"
-        filekey_txt_path = "../videoinfo/filekey.txt"
-
-        with open(filekey_txt_path, 'r', encoding="utf8") as f:
-            content = f.read()
-            print(content)
-            for line in content:
-                if filekey in line.strip():
-                    print("yes")
-                elif line.strip() == "":
-                    print("null")
-                else:
-                    print("no")
-
-    # 创建日志
-    @classmethod
-    def create_log(cls):
-        # 创建日志文件夹。如果不存在,则创建
-        log_dir = "../logs/"  # 日志文件夹名称
-        log_path = os.getcwd() + os.sep + log_dir  # 日志路径
-        if not os.path.isdir(log_path):
-            os.makedirs(log_path)
-
-        log_format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
-        date_format = "%Y-%m-%d %p %H:%M:%S"
-        # 初始化
-        logging.basicConfig(filename=log_path + 'logs.logs', level=logging.INFO, format=log_format, datefmt=date_format)
-
-        logger = logging.getLogger('shipinhao')
-
-        logger.info("这是第一条日志")
-
-    @classmethod
-    def split_title(cls):
-        title = Feishu.get_values_batch('demo', 'shipinhao', 'FSDlBy')[3][2]
-        print(title)
-        print('\n')
-        # print(title.split('\n')[0].split('#')[0])
-        print(title.split('\n')[0].replace('#', ''))
-
-    # 下载 、上传
-    @classmethod
-    def download_publish(cls, log_type, env):
-        try:
-            recommend_feeds_sheet = Feishu.get_values_batch(log_type, 'shipinhao', 'FSDlBy')
-            for i in range(1, len(recommend_feeds_sheet)):
-                download_title = recommend_feeds_sheet[i][2].strip().replace('"', '') \
-                    .replace('“', '').replace('“', '…').replace("\n", "") \
-                    .replace("/", "").replace("\r", "").replace("#", "") \
-                    .replace(".", "。").replace("\\", "").replace("&NBSP", "") \
-                    .replace(":", "").replace("*", "").replace("?", "") \
-                    .replace("?", "").replace('"', "").replace("<", "") \
-                    .replace(">", "").replace("|", "").replace(" ", "")
-                download_duration = recommend_feeds_sheet[i][3]
-                download_like_cnt = recommend_feeds_sheet[i][4]
-                download_share_cnt = recommend_feeds_sheet[i][5]
-                download_favorite_cnt = recommend_feeds_sheet[i][6]
-                download_comment_cnt = recommend_feeds_sheet[i][7]
-                download_username = recommend_feeds_sheet[i][8]
-                download_head_url = recommend_feeds_sheet[i][9]
-                download_cover_url = recommend_feeds_sheet[i][10]
-                download_video_url = recommend_feeds_sheet[i][11]
-
-                Common.logger(log_type).info("download_title:{}", download_title)
-                Common.logger(log_type).info("download_username:{}", download_username)
-                Common.logger(log_type).info("download_video_url:{}", download_video_url)
-
-                if download_title is None or download_duration is None or download_video_url is None:
-                    Feishu.dimension_range(log_type, 'shipinhao', 'FSDlBy', 'ROWS', i + 1, i + 1)
-                    Common.logger(log_type).info('空行,删除成功\n')
-                    return
-                elif str(download_title) in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'c77cf9') for x
-                                             in y]:
-                    Feishu.dimension_range(log_type, 'shipinhao', 'FSDlBy', 'ROWS', i + 1, i + 1)
-                    Common.logger(log_type).info('视频已下载,删除成功\n')
-                    return
-                else:
-                    # 下载封面
-                    Common.download_method(log_type=log_type, text="cover",
-                                           d_name=str(download_title), d_url=str(download_cover_url))
-                    # 下载视频
-                    Common.download_method(log_type=log_type, text="video",
-                                           d_name=str(download_title), d_url=str(download_video_url))
-                    # 保存视频信息至 "./videos/{download_video_title}/info.txt"
-                    with open("./videos/" + download_title
-                              + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
-                        f_a.write('shipinhao' + str(int(time.time())) + "\n" +
-                                  str(download_title) + "\n" +
-                                  str(download_duration) + "\n" +
-                                  str(download_favorite_cnt) + "\n" +
-                                  str(download_comment_cnt) + "\n" +
-                                  str(download_like_cnt) + "\n" +
-                                  str(download_share_cnt) + "\n" +
-                                  str(1920 * 1080) + "\n" +
-                                  str(int(time.time())) + "\n" +
-                                  str(download_username) + "\n" +
-                                  str(download_head_url) + "\n" +
-                                  str(download_video_url) + "\n" +
-                                  str(download_cover_url) + "\n" +
-                                  "shipinhao"+str(int(time.time())))
-                    Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
-
-                    Common.logger(log_type).info("开始上传视频:{}".format(download_title))
-                    our_video_id = Publish.upload_and_publish(log_type, env, "play")
-                    if env == 'dev':
-                        our_video_link = "https://testadmin.piaoquantv.com/cms/post-detail/" + str(our_video_id) + "/info"
-                    else:
-                        our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(our_video_id) + "/info"
-                    Common.logger(log_type).info("视频上传完成:{}", our_video_link)
-
-                    # # 视频ID工作表,插入首行
-                    # Feishu.insert_columns(log_type, "shipinhao", "c77cf9", "ROWS", 1, 2)
-                    # # 视频ID工作表,首行写入数据
-                    # upload_time = int(time.time())
-                    # values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(upload_time)),
-                    #            "话题榜",
-                    #            str(download_title),
-                    #            our_video_link,
-                    #            download_duration,
-                    #            download_like_cnt,
-                    #            download_share_cnt,
-                    #            download_favorite_cnt,
-                    #            download_comment_cnt,
-                    #            download_username,
-                    #            str(download_head_url),
-                    #            str(download_cover_url),
-                    #            str(download_video_url)]]
-                    # time.sleep(1)
-                    # Feishu.update_values(log_type, "shipinhao", "c77cf9", "F2:V2", values)
-
-                    # 删除行或列,可选 ROWS、COLUMNS
-                    time.sleep(1)
-                    Feishu.dimension_range(log_type, "shipinhao", "FSDlBy", "ROWS", i + 1, i + 1)
-                    Common.logger(log_type).info("下载/上传成功:{}\n", download_title)
-                    return
-        except Exception as e:
-            Feishu.dimension_range(log_type, "shipinhao", "FSDlBy", "ROWS", 2, 2)
-            Common.logger(log_type).error('download_publish异常,删除视频信息成功:{}\n', e)
-
-    @classmethod
-    def run_download_publish(cls, log_type, env):
-        while True:
-            feeds_sht = Feishu.get_values_batch(log_type, 'shipinhao', 'FSDlBy')
-            if len(feeds_sht) == 1:
-                Common.logger(log_type).info('下载/上传完成\n')
-                break
-            else:
-                cls.download_publish(log_type, env)
-
     @classmethod
     def get_sht(cls):
         sht = Feishu.get_values_batch('recommend', 'shipinhao', 'c77cf9')
@@ -212,6 +35,38 @@ class Demo:
         else:
             print('no')
 
+    @classmethod
+    def get_hotword(cls):
+        # 打印请求配置
+        ca = DesiredCapabilities.CHROME
+        ca["goog:loggingPrefs"] = {"performance": "ALL"}
+
+        # driver初始化
+        driver = webdriver.Chrome(desired_capabilities=ca)
+        # driver = webdriver.Chrome(desired_capabilities=ca, options=chrome_options)
+
+        driver.implicitly_wait(10)
+        print('打开百度网页')
+        driver.get('https://www.baidu.com/')
+        driver.maximize_window()
+        driver.implicitly_wait(10)
+
+        time.sleep(1)
+        hot_words = driver.find_elements(By.XPATH, '//li[@class="hotsearch-item odd"]')
+        for i in range(len(hot_words)):
+            print(i)
+            hot_word = hot_words[i].find_element(By.XPATH, '//span[@class="title-content-title"]')
+            print(hot_word)
+
+    # 比较字符串相似度
+    @classmethod
+    def str_similarity(cls):
+        str1 = '男童不小心将玩具扔到姑父身上,姑父一耳光将男童扇倒地。目前家人已报警处理,孩子身体检查无大碍。#家庭 #监控下的惊险一幕 '
+        str2 = '...姑父一耳光将男童扇倒地。目前家人已报警处理,孩子身体检查无大碍。#家庭 #监控下的惊险一幕'
+
+        print(difflib.SequenceMatcher(None, str1, str2).quick_ratio())
+        # print(type(difflib.SequenceMatcher(None, str1, str2).quick_ratio()))
+
 
 if __name__ == "__main__":
     Demo.get_sht()

+ 0 - 132
main/download_publish.py

@@ -1,132 +0,0 @@
-# -*- coding: utf-8 -*-
-# @Author: wangkun
-# @Time: 2022/9/1
-import os
-import random
-import sys
-import time
-sys.path.append(os.getcwd())
-from main.common import Common
-from main.feishu_lib import Feishu
-from main.publish import Publish
-
-
-class Download:
-    @classmethod
-    def download_publish(cls, log_type, env):
-        try:
-            recommend_sheet = Feishu.get_values_batch(log_type, 'shipinhao', 'FSDlBy')
-            for i in range(1, len(recommend_sheet)):
-                download_title = recommend_sheet[i][2].strip().replace('"', '') \
-                    .replace('“', '').replace('“', '…').replace("\n", "") \
-                    .replace("/", "").replace("\r", "").replace("#", "") \
-                    .replace(".", "。").replace("\\", "").replace("&NBSP", "") \
-                    .replace(":", "").replace("*", "").replace("?", "") \
-                    .replace("?", "").replace('"', "").replace("<", "") \
-                    .replace(">", "").replace("|", "").replace(" ", "")
-                download_duration = recommend_sheet[i][3]
-                download_like_cnt = recommend_sheet[i][4]
-                download_share_cnt = recommend_sheet[i][5]
-                download_favorite_cnt = recommend_sheet[i][6]
-                download_comment_cnt = recommend_sheet[i][7]
-                download_username = recommend_sheet[i][8]
-                download_head_url = recommend_sheet[i][9]
-                download_cover_url = recommend_sheet[i][10]
-                download_video_url = recommend_sheet[i][11]
-
-                Common.logger(log_type).info("download_title:{}", download_title)
-                Common.logger(log_type).info("download_username:{}", download_username)
-                Common.logger(log_type).info("download_video_url:{}", download_video_url)
-
-                # 判断空行
-                if download_video_url is None or download_title is None:
-                    Feishu.dimension_range(log_type, 'shipinhao', 'FSDlBy', 'ROWS', i + 1, i + 1)
-                    Common.logger(log_type).info("空行,删除成功\n")
-                    return
-                # 已下载判断
-                elif str(download_title) in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'c77cf9') for x in y]:
-                    Feishu.dimension_range(log_type, 'shipinhao', 'FSDlBy', 'ROWS', i + 1, i + 1)
-                    Common.logger(log_type).info("视频已下载\n")
-                    return
-                else:
-                    # 下载封面
-                    Common.download_method(log_type=log_type, text="cover",
-                                           d_name=str(download_title), d_url=str(download_cover_url))
-                    # 下载视频
-                    Common.download_method(log_type=log_type, text="video",
-                                           d_name=str(download_title), d_url=str(download_video_url))
-
-                    # 保存视频信息至 "./videos/{download_video_title}/info.txt"
-                    with open("./videos/" + download_title
-                              + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
-                        f_a.write('shipinhao' + str(int(time.time())) + "\n" +
-                                  str(download_title) + "\n" +
-                                  str(download_duration) + "\n" +
-                                  str(download_favorite_cnt) + "\n" +
-                                  str(download_comment_cnt) + "\n" +
-                                  str(download_like_cnt) + "\n" +
-                                  str(download_share_cnt) + "\n" +
-                                  str(1920*1080) + "\n" +
-                                  str(int(time.time())) + "\n" +
-                                  str(download_username) + "\n" +
-                                  str(download_head_url) + "\n" +
-                                  str(download_video_url) + "\n" +
-                                  str(download_cover_url) + "\n" +
-                                  "shipinhao")
-                    Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
-
-                    # 上传视频
-                    Common.logger(log_type).info("开始上传视频:{}".format(download_title))
-                    our_video_id = Publish.upload_and_publish(log_type, env, "play")
-                    if env == 'dev':
-                        our_video_link = "https://testadmin.piaoquantv.com/cms/post-detail/" + str(our_video_id) + "/info"
-                    else:
-                        our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(our_video_id) + "/info"
-                    Common.logger(log_type).info("视频上传完成:{}", download_title)
-
-                    # 视频ID工作表,插入首行
-                    Feishu.insert_columns(log_type, "shipinhao", "c77cf9", "ROWS", 1, 2)
-                    # 视频ID工作表,首行写入数据
-                    upload_time = int(time.time())
-                    values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(upload_time)),
-                               "推荐榜",
-                               str(download_title),
-                               our_video_link,
-                               download_duration,
-                               download_like_cnt,
-                               download_share_cnt,
-                               download_favorite_cnt,
-                               download_comment_cnt,
-                               str(download_username),
-                               str(download_head_url),
-                               str(download_cover_url),
-                               str(download_video_url)]]
-                    time.sleep(1)
-                    Feishu.update_values(log_type, "shipinhao", "c77cf9", "F2:Z2", values)
-
-                    # 删除行或列,可选 ROWS、COLUMNS
-                    Feishu.dimension_range(log_type, "shipinhao", "FSDlBy", "ROWS", i + 1, i + 1)
-                    Common.logger(log_type).info("视频:{},下载/上传成功\n", download_title)
-                    return
-        except Exception as e:
-            Common.logger(log_type).error("download_publish异常:{}\n", e)
-            Feishu.dimension_range(log_type, "shipinhao", "FSDlBy", "ROWS", 2, 2)
-
-    @classmethod
-    def run_download_publish(cls, log_type, env):
-        try:
-            while True:
-                time.sleep(1)
-                recommend_sheet = Feishu.get_values_batch(log_type, "shipinhao", "FSDlBy")
-                if len(recommend_sheet) == 1:
-                    Common.logger(log_type).info("下载/上传完成\n")
-                    break
-                else:
-                    cls.download_publish(log_type, env)
-                    time.sleep(random.randint(1, 3))
-        except Exception as e:
-            Common.logger(log_type).error("run_download_publish异常:{}", e)
-
-
-if __name__ == '__main__':
-    Download.run_download_publish('recommend', 'dev')

+ 33 - 0
main/run_shipinhao.py

@@ -0,0 +1,33 @@
+# -*- coding: utf-8 -*-
+# @Author: wangkun
+# @Time: 2022/10/27
+import datetime
+import os
+import sys
+import time
+sys.path.append(os.getcwd())
+from main.common import Common
+from shipinhao.shipinhao_recommend import Recommend
+from xinshi.xinshi_pc import XinshiPC
+
+
+class Main:
+    @classmethod
+    def main(cls, env):
+        while True:
+            # if 16 >= datetime.datetime.now().hour >= 10:
+            Common.logger('xinshi').info('开始抓取"新视-PC"内容\n')
+            XinshiPC.login('xinshi', env)
+
+            Recommend.run_recommend('recommend', env)
+            Common.del_logs('recommend')
+            Common.logger('recommend').info('休眠{}小时\n', 24 - datetime.datetime.now().hour)
+            Recommend.download_cnt = []
+            time.sleep(3600 * (24 - datetime.datetime.now().hour))
+
+            # else:
+            #     pass
+
+
+if __name__ == '__main__':
+    Main.main('prod')

+ 3 - 0
shipinhao/__init__.py

@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+# @Author: wangkun
+# @Time: 2022/10/27

+ 1 - 1
main/run_shipinhao_recommend.py → shipinhao/run_shipinhao_recommend.py

@@ -7,7 +7,7 @@ import sys
 import time
 sys.path.append(os.getcwd())
 from main.common import Common
-from main.shipinhao_recommend import Recommend
+from shipinhao.shipinhao_recommend import Recommend
 
 
 class Main:

+ 0 - 0
main/publish.py → shipinhao/shipinhao_publish.py


+ 1 - 1
main/shipinhao_recommend.py → shipinhao/shipinhao_recommend.py

@@ -11,7 +11,7 @@ from selenium.webdriver.common.by import By
 
 sys.path.append(os.getcwd())
 from main.common import Common
-from main.publish import Publish
+from shipinhao.shipinhao_publish import Publish
 from main.feishu_lib import Feishu
 
 

+ 0 - 0
main/shipinhao_topic.py → shipinhao/shipinhao_topic.py


+ 2 - 2
main/shipinhao_get_url.py → shipinhao/shipinhao_windows.py

@@ -13,7 +13,7 @@ from main.feishu_lib import Feishu
 from main.common import Common
 
 
-class GetUrl:
+class ShipinhaoWindows:
     @classmethod
     def kill_pid(cls, log_type):
         try:
@@ -161,7 +161,7 @@ class GetUrl:
 
 if __name__ == '__main__':
     while True:
-        GetUrl.run_get_url('recommend')
+        ShipinhaoWindows.run_get_url('recommend')
         Common.del_logs('recommend')
         time.sleep(1)
 

BIN
videos/.DS_Store


+ 0 - 49
xinshi/demo.py

@@ -1,49 +0,0 @@
-# -*- coding: utf-8 -*-
-# @Author: wangkun
-# @Time: 2022/10/25
-import difflib
-import time
-
-from selenium.webdriver import DesiredCapabilities
-from selenium.webdriver.common.by import By
-from seleniumwire import webdriver
-
-
-class Demo:
-    @classmethod
-    def get_hotword(cls):
-        # 打印请求配置
-        ca = DesiredCapabilities.CHROME
-        ca["goog:loggingPrefs"] = {"performance": "ALL"}
-
-        # driver初始化
-        driver = webdriver.Chrome(desired_capabilities=ca)
-        # driver = webdriver.Chrome(desired_capabilities=ca, options=chrome_options)
-
-        driver.implicitly_wait(10)
-        print('打开百度网页')
-        driver.get('https://www.baidu.com/')
-        driver.maximize_window()
-        driver.implicitly_wait(10)
-
-        time.sleep(1)
-        hot_words = driver.find_elements(By.XPATH, '//li[@class="hotsearch-item odd"]')
-        for i in range(len(hot_words)):
-            print(i)
-            hot_word = hot_words[i].find_element(By.XPATH, '//span[@class="title-content-title"]')
-            print(hot_word)
-
-    # 比较字符串相似度
-    @classmethod
-    def str_similarity(cls):
-        str1 = '男童不小心将玩具扔到姑父身上,姑父一耳光将男童扇倒地。目前家人已报警处理,孩子身体检查无大碍。#家庭 #监控下的惊险一幕 '
-        str2 = '...姑父一耳光将男童扇倒地。目前家人已报警处理,孩子身体检查无大碍。#家庭 #监控下的惊险一幕'
-
-        print(difflib.SequenceMatcher(None, str1, str2).quick_ratio())
-        # print(type(difflib.SequenceMatcher(None, str1, str2).quick_ratio()))
-
-
-if __name__ == '__main__':
-    # Demo.get_hotword()
-    Demo.str_similarity()
-    pass

+ 1 - 3
xinshi/run_xinshi.py

@@ -7,7 +7,6 @@ import sys
 import time
 sys.path.append(os.getcwd())
 from main.common import Common
-from xinshi.xinshi_app import XinshiAPP
 from xinshi.xinshi_pc import XinshiPC
 
 
@@ -15,13 +14,12 @@ class Main:
     @classmethod
     def main(cls, log_type, env):
         while True:
-            if datetime.datetime.now().hour <= 18:
+            if 10 <= datetime.datetime.now().hour <= 16:
                 Common.logger(log_type).info('开始抓取"新视-PC"内容\n')
                 XinshiPC.login(log_type, env)
 
                 Common.logger(log_type).info('休眠 1 分钟')
                 time.sleep(60)
-
                 Common.del_logs(log_type)
 
 

+ 407 - 412
xinshi/xinshi_app.py

@@ -22,44 +22,42 @@ class XinshiAPP:
 
     @classmethod
     def start_wechat(cls, log_type, env):
-        # try:
-        Common.logger(log_type).info('启动微信')
-        caps = {
-            "platformName": "Android",  # 手机操作系统 Android / iOS
-            "deviceName": "Android",  # 连接的设备名(模拟器或真机),安卓可以随便写
-            "platforVersion": "11",  # 手机对应的系统版本(Android 11)
-            "appPackage": "com.tencent.mm",  # 被测APP的包名,乐活圈 Android
-            "appActivity": ".ui.LauncherUI",  # 启动的Activity名
-            "autoGrantPermissions": True,  # 让 appium 自动授权 base 权限,
-            # 如果 noReset 为 True,则该条不生效(该参数为 Android 独有),对应的值为 True 或 False
-            "unicodekeyboard": True,  # 使用自带输入法,输入中文时填True
-            "resetkeyboard": True,  # 执行完程序恢复原来输入法
-            "noReset": True,  # 不重置APP
-            "recreateChromeDriverSessions": True,  # 切换到非 chrome-Driver 会 kill 掉 session,就不需要手动 kill 了
-            "printPageSourceOnFailure": True,  # 找不到元素时,appium log 会完整记录当前页面的 pagesource
-            "newCommandTimeout": 6000,  # 初始等待时间
-            "automationName": "UiAutomator2",  # 使用引擎,默认为 Appium,
-            # 其中 Appium、UiAutomator2、Selendroid、Espresso 用于 Android,XCUITest 用于 iOS
-            "showChromedriverLog": True,
-            # "chromeOptions": {"androidProcess": "com.tencent.mm:appbrand0"},
-            "chromeOptions": {"androidProcess": "com.tencent.mm:tools"},
-            'enableWebviewDetailsCollection': True,
-            'setWebContentsDebuggingEnabled': True,
-            'chromedriverExecutable': '/Users/wangkun/Downloads/chromedriver_v86/chromedriver',
-        }
-        driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
-        driver.implicitly_wait(10)
-
-        time.sleep(5)
-        Common.logger(log_type).info('开始抓取"新视-热门榜"')
-        cls.search_video(log_type, driver, 'gO4Sn4', env)
-        Common.logger(log_type).info('"新视-热门榜"抓取完毕\n')
-
-        Common.logger(log_type).info('开始抓取"新视-推荐榜"')
-        cls.search_video(log_type, driver, 'aOjaIU', env)
-        Common.logger(log_type).info('"新视-推荐榜"抓取完毕\n')
-        # except Exception as e:
-        #     Common.logger(log_type).error('start_wechat异常:{}\n', e)
+        try:
+            Common.logger(log_type).info('启动微信')
+            caps = {
+                "platformName": "Android",  # 手机操作系统 Android / iOS
+                "deviceName": "Android",  # 连接的设备名(模拟器或真机),安卓可以随便写
+                "platforVersion": "11",  # 手机对应的系统版本(Android 11)
+                "appPackage": "com.tencent.mm",  # 被测APP的包名,乐活圈 Android
+                "appActivity": ".ui.LauncherUI",  # 启动的Activity名
+                "autoGrantPermissions": True,  # 让 appium 自动授权 base 权限,
+                # 如果 noReset 为 True,则该条不生效(该参数为 Android 独有),对应的值为 True 或 False
+                "unicodekeyboard": True,  # 使用自带输入法,输入中文时填True
+                "resetkeyboard": True,  # 执行完程序恢复原来输入法
+                "noReset": True,  # 不重置APP
+                "recreateChromeDriverSessions": True,  # 切换到非 chrome-Driver 会 kill 掉 session,就不需要手动 kill 了
+                "printPageSourceOnFailure": True,  # 找不到元素时,appium log 会完整记录当前页面的 pagesource
+                "newCommandTimeout": 6000,  # 初始等待时间
+                "automationName": "UiAutomator2",  # 使用引擎,默认为 Appium,
+                # 其中 Appium、UiAutomator2、Selendroid、Espresso 用于 Android,XCUITest 用于 iOS
+                "showChromedriverLog": True,
+                # "chromeOptions": {"androidProcess": "com.tencent.mm:appbrand0"},
+                "chromeOptions": {"androidProcess": "com.tencent.mm:tools"},
+                'enableWebviewDetailsCollection': True,
+                'setWebContentsDebuggingEnabled': True,
+                'chromedriverExecutable': '/Users/wangkun/Downloads/chromedriver_v86/chromedriver',
+            }
+            driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
+            driver.implicitly_wait(10)
+
+            time.sleep(5)
+            # 搜索 新视-热门
+            cls.search_video(log_type, driver, 'gO4Sn4', env)
+            # 搜索 新视-推荐
+            cls.search_video(log_type, driver, 'aOjaIU', env)
+        except Exception as e:
+            Common.logger(log_type).error('start_wechat异常,重启APP:{}\n', e)
+            cls.start_wechat(log_type, env)
 
     @classmethod
     def search_element(cls, log_type, driver: WebDriver, element):
@@ -79,393 +77,390 @@ class XinshiAPP:
 
     @classmethod
     def search_video(cls, log_type, driver: WebDriver, sheetid, env):
-        # try:
-        sheet = Feishu.get_values_batch(log_type, 'shipinhao', sheetid)
-        if len(sheet) == 1:
-            Common.logger(log_type).info('暂无数据\n')
-            return
-        else:
-            for i in range(1, len(sheet)+1):
-                video_title = sheet[i][2]
-                video_user = sheet[i][3]
-
-                Common.logger(log_type).info('点击搜索按钮')
-                driver.find_element(By.ID, 'com.tencent.mm:id/j5t').click()
-
-                Common.logger(log_type).info('输入视频标题:{}', video_title)
-                time.sleep(3)
-                driver.find_element(By.ID, 'com.tencent.mm:id/cd7').clear().send_keys(video_title[:20])
-
-                Common.logger(log_type).info('点击搜索')
-                driver.press_keycode(AndroidKey.SEARCH)
-                driver.find_element(By.ID, 'com.tencent.mm:id/lm0').click()
-
-                Common.logger(log_type).info('切换到webview')
-                webview = driver.contexts
-                driver.switch_to.context(webview[1])
-
-                time.sleep(5)
-                video_list = cls.search_element(log_type, driver, '//div[@class="unit"]/*[2]')
-                Common.logger(log_type).info('点击"视频"分类')
-                video_list.click()
-
-                time.sleep(5)
-
-                # webview搜索并点击目标视频
-                while True:
-                    cls.i += 1
-                    title_element = cls.search_element(
-                        log_type, driver,
-                        '//div[@class="double-rich double-rich_vertical"]'
-                        '/*['+str(cls.i)+']//div[@class="title ellipsis_2"]')
-                    driver.execute_script(
-                        "arguments[0].scrollIntoView({block:'center',inline:'center'})", title_element)
-                    download_title = title_element.text
-                    download_user = cls.search_element(
-                        log_type, driver,
-                        '//div[@class="double-rich double-rich_vertical"]'
-                        '/*[' + str(cls.i) + ']//div[@class="vc-source"]').text.split('\n')[0]
-                    Common.logger(log_type).info('title:{}', download_title)
-                    Common.logger(log_type).info('user:{}\n', download_user)
-
-                    # 标题相似度>=50%, 用户名相似度>=80%
-                    # if video_title[:30] in download_title and video_user in download_user:
-                    if difflib.SequenceMatcher(None, video_title, download_title).quick_ratio() >= 0.5 \
-                            and difflib.SequenceMatcher(None, video_user, download_user).quick_ratio() >= 0.8:
-                        Common.logger(log_type).info('点击进入该视频详情')
-                        title_element.click()
-                        break
-
-                # 获取视频播放数据及播放地址
-                cls.get_video_info(log_type, driver, sheetid)
-
-                # 下载/上传
-                cls.xinshi_download_publish(log_type, sheetid, env)
-
-                # 恢复到微信首页
-                Common.logger(log_type).info('退出视频号')
-                driver.press_keycode(AndroidKey.BACK)
-                time.sleep(2)
-                Common.logger(log_type).info('点击"取消"')
-                driver.find_element(By.ID, 'com.tencent.mm:id/ki1').click()
-                time.sleep(2)
-                Common.logger(log_type).info('回到微信首页')
-                driver.find_element(By.ID, 'com.tencent.mm:id/apy').click()
-
-        # except Exception as e:
-        #     Common.logger(log_type).error('get_video_info_from_feishu异常:{}\n', e)
+        try:
+            sheet = Feishu.get_values_batch(log_type, 'shipinhao', sheetid)
+            if len(sheet) == 1:
+                Common.logger(log_type).info('暂无数据\n')
+                return
+            else:
+                for i in range(1, len(sheet)):
+                    driver.implicitly_wait(10)
+                    try:
+                        video_title = sheet[i][2]
+                        video_user = sheet[i][3]
+
+                        Common.logger(log_type).info('点击搜索按钮')
+                        driver.find_element(By.ID, 'com.tencent.mm:id/j5t').click()
+
+                        Common.logger(log_type).info('输入视频标题:{}', video_title)
+                        time.sleep(3)
+                        driver.find_element(By.ID, 'com.tencent.mm:id/cd7').clear().send_keys(video_title[:20])
+
+                        Common.logger(log_type).info('点击搜索')
+                        driver.press_keycode(AndroidKey.SEARCH)
+                        driver.find_element(By.ID, 'com.tencent.mm:id/lm0').click()
+
+                        Common.logger(log_type).info('切换到webview')
+                        webview = driver.contexts
+                        driver.switch_to.context(webview[1])
+
+                        time.sleep(5)
+                        video_list = cls.search_element(log_type, driver, '//div[@class="unit"]/*[2]')
+                        Common.logger(log_type).info('点击"视频"分类')
+                        video_list.click()
+
+                        time.sleep(8)
+                        # webview搜索并点击目标视频
+                        while True:
+                            cls.i += 1
+                            title_element = cls.search_element(
+                                log_type, driver,
+                                '//div[@class="double-rich double-rich_vertical"]'
+                                '/*['+str(cls.i)+']//div[@class="title ellipsis_2"]')
+                            driver.execute_script(
+                                "arguments[0].scrollIntoView({block:'center',inline:'center'})", title_element)
+                            download_title = title_element.text
+                            download_user = cls.search_element(
+                                log_type, driver,
+                                '//div[@class="double-rich double-rich_vertical"]'
+                                '/*[' + str(cls.i) + ']//div[@class="vc-source"]').text.split('\n')[0]
+                            Common.logger(log_type).info('title:{}', download_title)
+                            Common.logger(log_type).info('user:{}\n', download_user)
+
+                            # 标题相似度>=50%, 用户名相似度>=80%
+                            # if video_title[:30] in download_title and video_user in download_user:
+                            if difflib.SequenceMatcher(None, video_title, download_title).quick_ratio() >= 0.5 \
+                                    and difflib.SequenceMatcher(None, video_user, download_user).quick_ratio() >= 0.8:
+                                Common.logger(log_type).info('点击进入该视频详情')
+                                title_element.click()
+                                break
+
+                        # 获取视频播放数据及播放地址
+                        cls.get_video_info(log_type, driver, sheetid)
+                    except Exception:
+                        cls.start_wechat(log_type, env)
+
+                    # 下载/上传
+                    cls.xinshi_download_publish(log_type, sheetid, env)
+
+        except Exception as e:
+            Common.logger(log_type).error('search_video异常:{}\n', e)
 
     @classmethod
     def get_video_info(cls, log_type, driver: WebDriver, sheetid):
-        # webview = driver.contexts
-        Common.logger(log_type).info('切回NATIVE_APP\n')
-        driver.switch_to.context('NATIVE_APP')
-
-        # 点击播放器,获取视频时长
-        # Common.logger(log_type).info('暂停播放')
-        pause_btn = driver.find_element(By.ID, 'com.tencent.mm:id/eh4')
-        pause_btn.click()
-        start_time = driver.find_element(By.ID, 'com.tencent.mm:id/l59').get_attribute('name')
-        start_time = int(start_time.split(':')[0]) * 60 + int(start_time.split(':')[-1])
         try:
-            end_time = driver.find_element(By.ID, 'com.tencent.mm:id/l7i').get_attribute('name')
-        except NoSuchElementException:
-            end_time = driver.find_element(By.ID, 'com.tencent.mm:id/g73').get_attribute('name')
-        end_time = int(end_time.split(':')[0]) * 60 + int(end_time.split(':')[-1])
-        duration = start_time + end_time
-
-        # 点赞
-        like_id = driver.find_element(By.ID, 'com.tencent.mm:id/k04')
-        like_cnt = like_id.get_attribute('name')
-        if like_cnt == "" or like_cnt == "喜欢":
-            like_cnt = 0
-        elif '万' in like_cnt:
-            like_cnt = float(like_cnt.split('万')[0]) * 10000
-        elif '万+' in like_cnt:
-            like_cnt = float(like_cnt.split('万+')[0]) * 10000
-        else:
-            like_cnt = float(like_cnt)
-
-        # 分享
-        share_id = driver.find_element(By.ID, 'com.tencent.mm:id/jhv')
-        share_cnt = share_id.get_attribute('name')
-        if share_cnt == "" or share_cnt == "转发":
-            share_cnt = 0
-        elif '万' in share_cnt:
-            share_cnt = float(share_cnt.split('万')[0]) * 10000
-        elif '万+' in share_cnt:
-            share_cnt = float(share_cnt.split('万+')[0]) * 10000
-        else:
-            share_cnt = float(share_cnt)
-
-        # 收藏
-        favorite_id = driver.find_element(By.ID, 'com.tencent.mm:id/fnp')
-        favorite_cnt = favorite_id.get_attribute('name')
-        if favorite_cnt == "" or favorite_cnt == "收藏":
-            favorite_cnt = 0
-        elif '万' in favorite_cnt:
-            favorite_cnt = float(favorite_cnt.split('万')[0]) * 10000
-        elif '万+' in favorite_cnt:
-            favorite_cnt = float(favorite_cnt.split('万+')[0]) * 10000
-        else:
-            favorite_cnt = float(favorite_cnt)
-
-        # 评论
-        comment_id = driver.find_element(By.ID, 'com.tencent.mm:id/bje')
-        comment_cnt = comment_id.get_attribute('name')
-        if comment_cnt == "" or comment_cnt == "评论":
-            comment_cnt = 0
-        elif '万' in comment_cnt:
-            comment_cnt = float(comment_cnt.split('万')[0]) * 10000
-        elif '万+' in comment_cnt:
-            comment_cnt = float(comment_cnt.split('万+')[0]) * 10000
-        else:
-            comment_cnt = float(comment_cnt)
-
-        # 把视频信息写入飞书feeds文档
-        values = [[duration,
-                   like_cnt,
-                   share_cnt,
-                   favorite_cnt,
-                   comment_cnt]]
-        time.sleep(1)
-        Feishu.update_values(log_type, 'shipinhao', sheetid, 'E2:I2', values)
-        Common.logger(log_type).info('视频信息写入飞书文档成功\n')
-
-        # 分享给 windows 爬虫机
-        share_id.click()
-        driver.find_element(By.XPATH, '//*[@text="转发给朋友"]').click()
-        driver.find_element(By.XPATH, '//*[@text="爬虫群"]').click()
-        driver.find_element(By.ID, 'com.tencent.mm:id/guw').click()
-
-        while True:
-            if Feishu.get_values_batch(log_type, 'shipinhao', sheetid)[1][11] is None:
-                Common.logger(log_type).info('等待更新 URL 信息')
-                time.sleep(10)
+            # webview = driver.contexts
+            Common.logger(log_type).info('切回NATIVE_APP\n')
+            driver.switch_to.context('NATIVE_APP')
+
+            # 点击播放器,获取视频时长
+            # Common.logger(log_type).info('暂停播放')
+            pause_btn = driver.find_element(By.ID, 'com.tencent.mm:id/eh4')
+            pause_btn.click()
+            start_time = driver.find_element(By.ID, 'com.tencent.mm:id/l59').get_attribute('name')
+            start_time = int(start_time.split(':')[0]) * 60 + int(start_time.split(':')[-1])
+            try:
+                end_time = driver.find_element(By.ID, 'com.tencent.mm:id/l7i').get_attribute('name')
+            except NoSuchElementException:
+                end_time = driver.find_element(By.ID, 'com.tencent.mm:id/g73').get_attribute('name')
+            end_time = int(end_time.split(':')[0]) * 60 + int(end_time.split(':')[-1])
+            duration = start_time + end_time
+
+            # 点赞
+            like_id = driver.find_element(By.ID, 'com.tencent.mm:id/k04')
+            like_cnt = like_id.get_attribute('name')
+            if like_cnt == "" or like_cnt == "喜欢":
+                like_cnt = 0
+            elif '万' in like_cnt:
+                like_cnt = float(like_cnt.split('万')[0]) * 10000
+            elif '万+' in like_cnt:
+                like_cnt = float(like_cnt.split('万+')[0]) * 10000
+            else:
+                like_cnt = float(like_cnt)
+
+            # 分享
+            share_id = driver.find_element(By.ID, 'com.tencent.mm:id/jhv')
+            share_cnt = share_id.get_attribute('name')
+            if share_cnt == "" or share_cnt == "转发":
+                share_cnt = 0
+            elif '万' in share_cnt:
+                share_cnt = float(share_cnt.split('万')[0]) * 10000
+            elif '万+' in share_cnt:
+                share_cnt = float(share_cnt.split('万+')[0]) * 10000
             else:
-                Common.logger(log_type).info('URL 信息已更新\n')
-                break
+                share_cnt = float(share_cnt)
+
+            # 收藏
+            favorite_id = driver.find_element(By.ID, 'com.tencent.mm:id/fnp')
+            favorite_cnt = favorite_id.get_attribute('name')
+            if favorite_cnt == "" or favorite_cnt == "收藏":
+                favorite_cnt = 0
+            elif '万' in favorite_cnt:
+                favorite_cnt = float(favorite_cnt.split('万')[0]) * 10000
+            elif '万+' in favorite_cnt:
+                favorite_cnt = float(favorite_cnt.split('万+')[0]) * 10000
+            else:
+                favorite_cnt = float(favorite_cnt)
+
+            # 评论
+            comment_id = driver.find_element(By.ID, 'com.tencent.mm:id/bje')
+            comment_cnt = comment_id.get_attribute('name')
+            if comment_cnt == "" or comment_cnt == "评论":
+                comment_cnt = 0
+            elif '万' in comment_cnt:
+                comment_cnt = float(comment_cnt.split('万')[0]) * 10000
+            elif '万+' in comment_cnt:
+                comment_cnt = float(comment_cnt.split('万+')[0]) * 10000
+            else:
+                comment_cnt = float(comment_cnt)
+
+            # 把视频信息写入飞书feeds文档
+            values = [[duration,
+                       like_cnt,
+                       share_cnt,
+                       favorite_cnt,
+                       comment_cnt]]
+            time.sleep(1)
+            Feishu.update_values(log_type, 'shipinhao', sheetid, 'E2:I2', values)
+            Common.logger(log_type).info('视频信息写入飞书文档成功\n')
+
+            # 分享给 windows 爬虫机
+            share_id.click()
+            driver.find_element(By.XPATH, '//*[@text="转发给朋友"]').click()
+            driver.find_element(By.XPATH, '//*[@text="爬虫群"]').click()
+            driver.find_element(By.ID, 'com.tencent.mm:id/guw').click()
+
+            while True:
+                if Feishu.get_values_batch(log_type, 'shipinhao', sheetid)[1][11] is None:
+                    Common.logger(log_type).info('等待更新 URL 信息')
+                    time.sleep(10)
+                else:
+                    Common.logger(log_type).info('URL 信息已更新\n')
+                    break
+
+        except Exception as e:
+            Common.logger(log_type).error('get_video_info异常:{}\n', e)
 
     @classmethod
     def xinshi_download_publish(cls, log_type, sheetid, env):
-        # try:
-        download_sheet = Feishu.get_values_batch(log_type, 'shipinhao', sheetid)
-        for i in range(1, len(download_sheet)):
-            download_title = download_sheet[i][2].strip().replace('"', '') \
-                .replace('“', '').replace('“', '…').replace("\n", "") \
-                .replace("/", "").replace("\r", "").replace("#", "") \
-                .replace(".", "。").replace("\\", "").replace("&NBSP", "") \
-                .replace(":", "").replace("*", "").replace("?", "") \
-                .replace("?", "").replace('"', "").replace("<", "") \
-                .replace(">", "").replace("|", "").replace(" ", "")
-            download_duration = download_sheet[i][3]
-            download_like_cnt = download_sheet[i][4]
-            download_share_cnt = download_sheet[i][5]
-            download_favorite_cnt = download_sheet[i][6]
-            download_comment_cnt = download_sheet[i][7]
-            download_username = download_sheet[i][8]
-            download_head_url = download_sheet[i][9]
-            download_cover_url = download_sheet[i][10]
-            download_video_url = download_sheet[i][11]
-
-            Common.logger(log_type).info("download_title:{}", download_title)
-            Common.logger(log_type).info("download_username:{}", download_username)
-            Common.logger(log_type).info("download_video_url:{}", download_video_url)
-
-            if download_title is None or download_duration is None or download_video_url is None:
-                Feishu.dimension_range(log_type, 'shipinhao', sheetid, 'ROWS', i + 1, i + 1)
-                Common.logger(log_type).info('空行,删除成功\n')
-                return
-            elif str(download_title) in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'c77cf9') for x
-                                         in y]:
-                Feishu.dimension_range(log_type, 'shipinhao', sheetid, 'ROWS', i + 1, i + 1)
-                Common.logger(log_type).info('视频已下载,删除成功\n')
-                return
-            elif str(download_title) in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'WAG7Dq') for x
-                                         in y]:
-                Feishu.dimension_range(log_type, 'shipinhao', sheetid, 'ROWS', i + 1, i + 1)
-                Common.logger(log_type).info('视频已下载,删除成功\n')
-                return
-            elif str(download_title) in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', '0i4jmV') for x
-                                         in y]:
-                Feishu.dimension_range(log_type, 'shipinhao', sheetid, 'ROWS', i + 1, i + 1)
-                Common.logger(log_type).info('视频已下载,删除成功\n')
-                return
-            elif str(download_title) in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'c77cf9') for x
-                                         in y]:
-                Feishu.dimension_range(log_type, 'shipinhao', sheetid, 'ROWS', i + 1, i + 1)
-                Common.logger(log_type).info('视频已存在,删除成功\n')
-                return
-            else:
-                # 下载封面
-                Common.download_method(log_type=log_type, text="cover",
-                                       d_name=str(download_title), d_url=str(download_cover_url))
-                # 下载视频
-                Common.download_method(log_type=log_type, text="video",
-                                       d_name=str(download_title), d_url=str(download_video_url))
-                # 保存视频信息至 "./videos/{download_video_title}/info.txt"
-                with open("./videos/" + download_title
-                          + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
-                    f_a.write('shipinhao' + str(int(time.time())) + "\n" +
-                              str(download_title) + "\n" +
-                              str(download_duration) + "\n" +
-                              str(download_favorite_cnt) + "\n" +
-                              str(download_comment_cnt) + "\n" +
-                              str(download_like_cnt) + "\n" +
-                              str(download_share_cnt) + "\n" +
-                              str(1920 * 1080) + "\n" +
-                              str(int(time.time())) + "\n" +
-                              str(download_username) + "\n" +
-                              str(download_head_url) + "\n" +
-                              str(download_video_url) + "\n" +
-                              str(download_cover_url) + "\n" +
-                              "shipinhao")
-                Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
-
-                Common.logger(log_type).info("开始上传视频:{}".format(download_title))
-                if env == 'dev' and sheetid == 'gO4Sn4':
-                    our_video_id = Publish.upload_and_publish(log_type, env, "xinshi_hot")
-                    our_video_link = "https://testadmin.piaoquantv.com/cms/post-detail/"+str(our_video_id)+"/info"
-                    # 视频ID工作表,插入首行
-                    Feishu.insert_columns(log_type, "shipinhao", '0i4jmV', "ROWS", 1, 2)
-                    # 视频ID工作表,首行写入数据
-                    upload_time = int(time.time())
-                    values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(upload_time)),
-                               "新视-热门榜",
-                               str(download_title),
-                               our_video_link,
-                               download_duration,
-                               download_like_cnt,
-                               download_share_cnt,
-                               download_favorite_cnt,
-                               download_comment_cnt,
-                               download_username,
-                               str(download_head_url),
-                               str(download_cover_url),
-                               str(download_video_url)]]
-                    time.sleep(1)
-                    Feishu.update_values(log_type, "shipinhao", '0i4jmV', "F2:V2", values)
-
-                    # 删除行或列,可选 ROWS、COLUMNS
-                    time.sleep(1)
-                    Feishu.dimension_range(log_type, "shipinhao", sheetid, "ROWS", i + 1, i + 1)
-                    Common.logger(log_type).info("视频上传完成:{}\n", our_video_link)
+        try:
+            download_sheet = Feishu.get_values_batch(log_type, 'shipinhao', sheetid)
+            for i in range(1, len(download_sheet)):
+                download_title = download_sheet[i][2].strip().replace('"', '') \
+                    .replace('“', '').replace('“', '…').replace("\n", "") \
+                    .replace("/", "").replace("\r", "").replace("#", "") \
+                    .replace(".", "。").replace("\\", "").replace("&NBSP", "") \
+                    .replace(":", "").replace("*", "").replace("?", "") \
+                    .replace("?", "").replace('"', "").replace("<", "") \
+                    .replace(">", "").replace("|", "").replace(" ", "")
+                download_duration = download_sheet[i][4]
+                download_like_cnt = download_sheet[i][5]
+                download_share_cnt = download_sheet[i][6]
+                download_favorite_cnt = download_sheet[i][7]
+                download_comment_cnt = download_sheet[i][8]
+                download_username = download_sheet[i][3]
+                download_head_url = download_sheet[i][9]
+                download_cover_url = download_sheet[i][10]
+                download_video_url = download_sheet[i][11]
+
+                Common.logger(log_type).info("download_title:{}", download_title)
+                Common.logger(log_type).info("download_username:{}", download_username)
+                Common.logger(log_type).info("download_video_url:{}", download_video_url)
+
+                if download_title is None or download_duration is None or download_video_url is None:
+                    Feishu.dimension_range(log_type, 'shipinhao', sheetid, 'ROWS', i + 1, i + 1)
+                    Common.logger(log_type).info('空行,删除成功\n')
                     return
-                elif env == 'dev' and sheetid == 'aOjaIU':
-                    our_video_id = Publish.upload_and_publish(log_type, env, "xinshi_recommend")
-                    our_video_link = "https://testadmin.piaoquantv.com/cms/post-detail/"+str(our_video_id)+"/info"
-                    # 视频ID工作表,插入首行
-                    Feishu.insert_columns(log_type, "shipinhao", 'WAG7Dq', "ROWS", 1, 2)
-                    # 视频ID工作表,首行写入数据
-                    upload_time = int(time.time())
-                    values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(upload_time)),
-                               "新视-推荐榜",
-                               str(download_title),
-                               our_video_link,
-                               download_duration,
-                               download_like_cnt,
-                               download_share_cnt,
-                               download_favorite_cnt,
-                               download_comment_cnt,
-                               download_username,
-                               str(download_head_url),
-                               str(download_cover_url),
-                               str(download_video_url)]]
-                    time.sleep(1)
-                    Feishu.update_values(log_type, "shipinhao", 'WAG7Dq', "F2:V2", values)
-
-                    # 删除行或列,可选 ROWS、COLUMNS
-                    time.sleep(1)
-                    Feishu.dimension_range(log_type, "shipinhao", sheetid, "ROWS", i + 1, i + 1)
-                    Common.logger(log_type).info("视频上传完成:{}\n", our_video_link)
+                elif str(download_title) in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'c77cf9') for x
+                                             in y]:
+                    Feishu.dimension_range(log_type, 'shipinhao', sheetid, 'ROWS', i + 1, i + 1)
+                    Common.logger(log_type).info('视频已下载,删除成功\n')
                     return
-                elif env == 'prod' and sheetid == 'gO4Sn4':
-                    our_video_id = Publish.upload_and_publish(log_type, env, "xinshi_hot")
-                    our_video_link = "https://testadmin.piaoquantv.com/cms/post-detail/"+str(our_video_id)+"/info"
-                    # 视频ID工作表,插入首行
-                    Feishu.insert_columns(log_type, "shipinhao", '0i4jmV', "ROWS", 1, 2)
-                    # 视频ID工作表,首行写入数据
-                    upload_time = int(time.time())
-                    values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(upload_time)),
-                               "新视-热门榜",
-                               str(download_title),
-                               our_video_link,
-                               download_duration,
-                               download_like_cnt,
-                               download_share_cnt,
-                               download_favorite_cnt,
-                               download_comment_cnt,
-                               download_username,
-                               str(download_head_url),
-                               str(download_cover_url),
-                               str(download_video_url)]]
-                    time.sleep(1)
-                    Feishu.update_values(log_type, "shipinhao", '0i4jmV', "F2:V2", values)
-
-                    # 删除行或列,可选 ROWS、COLUMNS
-                    time.sleep(1)
-                    Feishu.dimension_range(log_type, "shipinhao", sheetid, "ROWS", i + 1, i + 1)
-                    Common.logger(log_type).info("视频上传完成:{}\n", our_video_link)
+                elif str(download_title) in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'WAG7Dq') for x
+                                             in y]:
+                    Feishu.dimension_range(log_type, 'shipinhao', sheetid, 'ROWS', i + 1, i + 1)
+                    Common.logger(log_type).info('视频已下载,删除成功\n')
                     return
-                elif env == 'prod' and sheetid == 'aOjaIU':
-                    our_video_id = Publish.upload_and_publish(log_type, env, "xinshi_recommend")
-                    our_video_link = "https://testadmin.piaoquantv.com/cms/post-detail/"+str(our_video_id)+"/info"
-                    # 视频ID工作表,插入首行
-                    Feishu.insert_columns(log_type, "shipinhao", 'WAG7Dq', "ROWS", 1, 2)
-                    # 视频ID工作表,首行写入数据
-                    upload_time = int(time.time())
-                    values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(upload_time)),
-                               "新视-热门榜",
-                               str(download_title),
-                               our_video_link,
-                               download_duration,
-                               download_like_cnt,
-                               download_share_cnt,
-                               download_favorite_cnt,
-                               download_comment_cnt,
-                               download_username,
-                               str(download_head_url),
-                               str(download_cover_url),
-                               str(download_video_url)]]
-                    time.sleep(1)
-                    Feishu.update_values(log_type, "shipinhao", 'WAG7Dq', "F2:V2", values)
-
-                    # 删除行或列,可选 ROWS、COLUMNS
-                    time.sleep(1)
-                    Feishu.dimension_range(log_type, "shipinhao", sheetid, "ROWS", i + 1, i + 1)
-                    Common.logger(log_type).info("视频上传完成:{}\n", our_video_link)
+                elif str(download_title) in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', '0i4jmV') for x
+                                             in y]:
+                    Feishu.dimension_range(log_type, 'shipinhao', sheetid, 'ROWS', i + 1, i + 1)
+                    Common.logger(log_type).info('视频已下载,删除成功\n')
                     return
-                else:
-                    our_video_id = Publish.upload_and_publish(log_type, env, "xinshi_hot")
-                    our_video_link = "https://admin.piaoquantv.com/cms/post-detail/"+str(our_video_id)+"/info"
-                    # 视频ID工作表,插入首行
-                    Feishu.insert_columns(log_type, "shipinhao", 'WAG7Dq', "ROWS", 1, 2)
-                    # 视频ID工作表,首行写入数据
-                    upload_time = int(time.time())
-                    values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(upload_time)),
-                               "新视-热门榜",
-                               str(download_title),
-                               our_video_link,
-                               download_duration,
-                               download_like_cnt,
-                               download_share_cnt,
-                               download_favorite_cnt,
-                               download_comment_cnt,
-                               download_username,
-                               str(download_head_url),
-                               str(download_cover_url),
-                               str(download_video_url)]]
-                    time.sleep(1)
-                    Feishu.update_values(log_type, "shipinhao", 'WAG7Dq', "F2:V2", values)
-
-                    # 删除行或列,可选 ROWS、COLUMNS
-                    time.sleep(1)
-                    Feishu.dimension_range(log_type, "shipinhao", sheetid, "ROWS", i + 1, i + 1)
-                    Common.logger(log_type).info("视频上传完成:{}\n", our_video_link)
+                elif str(download_title) in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'c77cf9') for x
+                                             in y]:
+                    Feishu.dimension_range(log_type, 'shipinhao', sheetid, 'ROWS', i + 1, i + 1)
+                    Common.logger(log_type).info('视频已存在,删除成功\n')
                     return
-        # except Exception as e:
-        #     Feishu.dimension_range(log_type, "shipinhao", "FSDlBy", "ROWS", 2, 2)
-        #     Common.logger(log_type).error('download_publish异常,删除视频信息成功:{}\n', e)
+                else:
+                    # 下载封面
+                    Common.download_method(log_type=log_type, text="cover",
+                                           d_name=str(download_title), d_url=str(download_cover_url))
+                    # 下载视频
+                    Common.download_method(log_type=log_type, text="video",
+                                           d_name=str(download_title), d_url=str(download_video_url))
+                    # 保存视频信息至 "./videos/{download_video_title}/info.txt"
+                    with open("./videos/" + download_title
+                              + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
+                        f_a.write('shipinhao' + str(int(time.time())) + "\n" +
+                                  str(download_title) + "\n" +
+                                  str(download_duration) + "\n" +
+                                  str(download_favorite_cnt) + "\n" +
+                                  str(download_comment_cnt) + "\n" +
+                                  str(download_like_cnt) + "\n" +
+                                  str(download_share_cnt) + "\n" +
+                                  str(1920 * 1080) + "\n" +
+                                  str(int(time.time())) + "\n" +
+                                  str(download_username) + "\n" +
+                                  str(download_head_url) + "\n" +
+                                  str(download_video_url) + "\n" +
+                                  str(download_cover_url) + "\n" +
+                                  "shipinhao")
+                    Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
+
+                    Common.logger(log_type).info("开始上传视频:{}".format(download_title))
+                    if env == 'dev' and sheetid == 'gO4Sn4':
+                        our_video_id = Publish.upload_and_publish(log_type, env, "xinshi_hot")
+                        our_video_link = "https://testadmin.piaoquantv.com/cms/post-detail/"+str(our_video_id)+"/info"
+                        # 视频ID工作表,插入首行
+                        Feishu.insert_columns(log_type, "shipinhao", '0i4jmV', "ROWS", 1, 2)
+                        # 视频ID工作表,首行写入数据
+                        upload_time = int(time.time())
+                        values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(upload_time)),
+                                   "新视-热门榜",
+                                   str(download_title),
+                                   our_video_link,
+                                   download_duration,
+                                   download_like_cnt,
+                                   download_share_cnt,
+                                   download_favorite_cnt,
+                                   download_comment_cnt,
+                                   download_username,
+                                   str(download_head_url),
+                                   str(download_cover_url),
+                                   str(download_video_url)]]
+                        time.sleep(1)
+                        Feishu.update_values(log_type, "shipinhao", '0i4jmV', "F2:V2", values)
+
+                        # 删除行或列,可选 ROWS、COLUMNS
+                        time.sleep(1)
+                        Feishu.dimension_range(log_type, "shipinhao", sheetid, "ROWS", i + 1, i + 1)
+                        Common.logger(log_type).info("视频上传完成:{}\n", our_video_link)
+                        return
+                    elif env == 'dev' and sheetid == 'aOjaIU':
+                        our_video_id = Publish.upload_and_publish(log_type, env, "xinshi_recommend")
+                        our_video_link = "https://testadmin.piaoquantv.com/cms/post-detail/"+str(our_video_id)+"/info"
+                        # 视频ID工作表,插入首行
+                        Feishu.insert_columns(log_type, "shipinhao", 'WAG7Dq', "ROWS", 1, 2)
+                        # 视频ID工作表,首行写入数据
+                        upload_time = int(time.time())
+                        values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(upload_time)),
+                                   "新视-推荐榜",
+                                   str(download_title),
+                                   our_video_link,
+                                   download_duration,
+                                   download_like_cnt,
+                                   download_share_cnt,
+                                   download_favorite_cnt,
+                                   download_comment_cnt,
+                                   download_username,
+                                   str(download_head_url),
+                                   str(download_cover_url),
+                                   str(download_video_url)]]
+                        time.sleep(1)
+                        Feishu.update_values(log_type, "shipinhao", 'WAG7Dq', "F2:V2", values)
+
+                        # 删除行或列,可选 ROWS、COLUMNS
+                        time.sleep(1)
+                        Feishu.dimension_range(log_type, "shipinhao", sheetid, "ROWS", i + 1, i + 1)
+                        Common.logger(log_type).info("视频上传完成:{}\n", our_video_link)
+                        return
+                    elif env == 'prod' and sheetid == 'gO4Sn4':
+                        our_video_id = Publish.upload_and_publish(log_type, env, "xinshi_hot")
+                        our_video_link = "https://admin.piaoquantv.com/cms/post-detail/"+str(our_video_id)+"/info"
+                        # 视频ID工作表,插入首行
+                        Feishu.insert_columns(log_type, "shipinhao", '0i4jmV', "ROWS", 1, 2)
+                        # 视频ID工作表,首行写入数据
+                        upload_time = int(time.time())
+                        values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(upload_time)),
+                                   "新视-热门榜",
+                                   str(download_title),
+                                   our_video_link,
+                                   download_duration,
+                                   download_like_cnt,
+                                   download_share_cnt,
+                                   download_favorite_cnt,
+                                   download_comment_cnt,
+                                   download_username,
+                                   str(download_head_url),
+                                   str(download_cover_url),
+                                   str(download_video_url)]]
+                        time.sleep(1)
+                        Feishu.update_values(log_type, "shipinhao", '0i4jmV', "F2:V2", values)
+
+                        # 删除行或列,可选 ROWS、COLUMNS
+                        time.sleep(1)
+                        Feishu.dimension_range(log_type, "shipinhao", sheetid, "ROWS", i + 1, i + 1)
+                        Common.logger(log_type).info("视频上传完成:{}\n", our_video_link)
+                        return
+                    elif env == 'prod' and sheetid == 'aOjaIU':
+                        our_video_id = Publish.upload_and_publish(log_type, env, "xinshi_recommend")
+                        our_video_link = "https://admin.piaoquantv.com/cms/post-detail/"+str(our_video_id)+"/info"
+                        # 视频ID工作表,插入首行
+                        Feishu.insert_columns(log_type, "shipinhao", 'WAG7Dq', "ROWS", 1, 2)
+                        # 视频ID工作表,首行写入数据
+                        upload_time = int(time.time())
+                        values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(upload_time)),
+                                   "新视-热门榜",
+                                   str(download_title),
+                                   our_video_link,
+                                   download_duration,
+                                   download_like_cnt,
+                                   download_share_cnt,
+                                   download_favorite_cnt,
+                                   download_comment_cnt,
+                                   download_username,
+                                   str(download_head_url),
+                                   str(download_cover_url),
+                                   str(download_video_url)]]
+                        time.sleep(1)
+                        Feishu.update_values(log_type, "shipinhao", 'WAG7Dq', "F2:V2", values)
+
+                        # 删除行或列,可选 ROWS、COLUMNS
+                        time.sleep(1)
+                        Feishu.dimension_range(log_type, "shipinhao", sheetid, "ROWS", i + 1, i + 1)
+                        Common.logger(log_type).info("视频上传完成:{}\n", our_video_link)
+                        return
+                    else:
+                        our_video_id = Publish.upload_and_publish(log_type, env, "xinshi_hot")
+                        our_video_link = "https://admin.piaoquantv.com/cms/post-detail/"+str(our_video_id)+"/info"
+                        # 视频ID工作表,插入首行
+                        Feishu.insert_columns(log_type, "shipinhao", 'WAG7Dq', "ROWS", 1, 2)
+                        # 视频ID工作表,首行写入数据
+                        upload_time = int(time.time())
+                        values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(upload_time)),
+                                   "新视-热门榜",
+                                   str(download_title),
+                                   our_video_link,
+                                   download_duration,
+                                   download_like_cnt,
+                                   download_share_cnt,
+                                   download_favorite_cnt,
+                                   download_comment_cnt,
+                                   download_username,
+                                   str(download_head_url),
+                                   str(download_cover_url),
+                                   str(download_video_url)]]
+                        time.sleep(1)
+                        Feishu.update_values(log_type, "shipinhao", 'WAG7Dq', "F2:V2", values)
+
+                        # 删除行或列,可选 ROWS、COLUMNS
+                        time.sleep(1)
+                        Feishu.dimension_range(log_type, "shipinhao", sheetid, "ROWS", i + 1, i + 1)
+                        Common.logger(log_type).info("视频上传完成:{}\n", our_video_link)
+                        return
+        except Exception as e:
+            Feishu.dimension_range(log_type, "shipinhao", "FSDlBy", "ROWS", 2, 2)
+            Common.logger(log_type).error('download_publish异常,删除视频信息成功:{}\n', e)
 
 
 if __name__ == '__main__':

+ 24 - 11
xinshi/xinshi_pc.py

@@ -6,6 +6,7 @@ import sys
 import time
 from selenium.common import NoSuchElementException
 from selenium.webdriver import DesiredCapabilities, ActionChains
+from selenium.webdriver.chrome.service import Service
 from selenium.webdriver.common.by import By
 from seleniumwire import webdriver
 
@@ -22,17 +23,17 @@ class XinshiPC:
         ca = DesiredCapabilities.CHROME
         ca["goog:loggingPrefs"] = {"performance": "ALL"}
 
-        # # 不打开浏览器运行
-        # chrome_options = webdriver.ChromeOptions()
-        # chrome_options.add_argument("headless")
-        # chrome_options.add_argument(
-        #     f'user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36')
-        # chrome_options.add_argument("--no-sandbox")
+        # 不打开浏览器运行
+        chrome_options = webdriver.ChromeOptions()
+        chrome_options.add_argument("headless")
+        chrome_options.add_argument(
+            f'user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36')
+        chrome_options.add_argument("--no-sandbox")
 
         # driver初始化
         # Common.logger(log_type).info('初始化 webdriver')
-        driver = webdriver.Chrome(desired_capabilities=ca)
-        # driver = webdriver.Chrome(desired_capabilities=ca, options=chrome_options)
+        # driver = webdriver.Chrome(desired_capabilities=ca)
+        driver = webdriver.Chrome(desired_capabilities=ca, options=chrome_options, service=Service('/Users/wangkun/Downloads/chromedriver_v106/chromedriver'))
 
         driver.implicitly_wait(10)
         Common.logger(log_type).info('打开网页"新视-热门内容"')
@@ -91,7 +92,7 @@ class XinshiPC:
         except NoSuchElementException:
             Common.logger(log_type).info('登录失败,重新登录\n')
             driver.quit()
-            cls.login(log_type)
+            cls.login(log_type, env)
 
         # 获取热门内容
         cls.get_recenhot(log_type, driver, env)
@@ -112,7 +113,13 @@ class XinshiPC:
         for i in range(1, 21):
             video_title = driver.find_element(
                 By.XPATH, '//div[@class="_6gxA3h-x"]/*[' + str(i) + ']//div[@class="_hsgIoLGN"]'
-            ).get_attribute('title').replace('\n', '')
+            ).get_attribute('title').strip().replace('"', '') \
+                .replace('“', '').replace('“', '…').replace("\n", "") \
+                .replace("/", "").replace("\r", "").replace("#", "") \
+                .replace(".", "。").replace("\\", "").replace("&NBSP", "") \
+                .replace(":", "").replace("*", "").replace("?", "") \
+                .replace("?", "").replace('"', "").replace("<", "") \
+                .replace(">", "").replace("|", "").replace(" ", "")
             user_name = driver.find_element(
                 By.XPATH, '//div[@class="_6gxA3h-x"]/*[' + str(i) + ']//div[@class="_zoylmQ8m"]'
             ).get_attribute('title').replace('\n', '')
@@ -159,7 +166,13 @@ class XinshiPC:
             Common.logger(log_type).info('开始抓取第{}条', i)
             video_title = driver.find_element(
                 By.XPATH, '//div[@class="_tCg-GF3J"]/*['+str(i)+']//div[@class="_EmoRHgxz"]'
-            ).get_attribute('title').replace('\n', '')
+            ).get_attribute('title').strip().replace('"', '') \
+                .replace('“', '').replace('“', '…').replace("\n", "") \
+                .replace("/", "").replace("\r", "").replace("#", "") \
+                .replace(".", "。").replace("\\", "").replace("&NBSP", "") \
+                .replace(":", "").replace("*", "").replace("?", "") \
+                .replace("?", "").replace('"', "").replace("<", "") \
+                .replace(">", "").replace("|", "").replace(" ", "")
             user_name = driver.find_element(
                 By.XPATH, '//div[@class="_tCg-GF3J"]/*['+str(i)+']//div[@class="_gD23uy8R"]'
             ).get_attribute('title').replace('\n', '')

+ 2 - 2
xinshi/xinshi_publish.py

@@ -35,7 +35,7 @@ class Publish:
         versionCode  版本 默认1
         :return:
         """
-        # Common.logger().info('publish request data: {}'.format(request_data))
+        # Common.logger(log_type).info('publish request data: {}'.format(request_data))
         result = cls.request_post('https://videotest.yishihui.com/longvideoapi/crawler/video/send', request_data)
         # Common.logger(log_type).info('publish result: {}'.format(result))
         video_id = result["data"]["id"]
@@ -256,5 +256,5 @@ class Publish:
                     Common.logger(log_type).error('file not a dir = {}'.format(fi_d))
             except Exception as e:
                 # 删除视频文件夹
-                shutil.rmtree("./videos/" + f + "/")
+                shutil.rmtree("./videos/" + str(f) + "/")
                 Common.logger(log_type).exception('upload_and_publish error', e)