瀏覽代碼

add xinshi

wangkun 2 年之前
父節點
當前提交
40d448b9a7
共有 10 個文件被更改,包括 1136 次插入6 次删除
  1. 二進制
      .DS_Store
  2. 2 0
      .gitignore
  3. 3 0
      README.md
  4. 1 6
      main/common.py
  5. 3 0
      xinshi/__init__.py
  6. 37 0
      xinshi/demo.py
  7. 468 0
      xinshi/xinshi_app.py
  8. 192 0
      xinshi/xinshi_pc.py
  9. 260 0
      xinshi/xinshi_publish.py
  10. 170 0
      xinshi/xinshi_windows.py

二進制
.DS_Store


+ 2 - 0
.gitignore

@@ -7,6 +7,7 @@ __pycache__/
 *.so
 
 # Distribution / packaging
+.DS_Store
 .Python
 build/
 develop-eggs/
@@ -105,6 +106,7 @@ celerybeat.pid
 *.sage.py
 
 # Environments
+.DS_Store
 .env
 .venv
 env/

+ 3 - 0
README.md

@@ -24,6 +24,9 @@
 
 
 #### 需求
+2022/10/27
+1. 新增新视榜单爬虫
+
 2022/10/18
 1. 运行时间调整: 10:00:00 - 16:00:00 (包含)
 

+ 1 - 6
main/common.py

@@ -38,12 +38,7 @@ class Common:
             os.makedirs(log_path)
 
         # 日志文件名
-        if log_type == "recommend":
-            log_name = time.strftime("%Y-%m-%d", time.localtime(time.time())) + '-shipinhao-recommend.log'
-        elif log_type == "topic":
-            log_name = time.strftime("%Y-%m-%d", time.localtime(time.time())) + '-shipinhao-topic.log'
-        else:
-            log_name = time.strftime("%Y-%m-%d", time.localtime(time.time())) + '-shipinhao.log'
+        log_name = time.strftime("%Y-%m-%d", time.localtime(time.time())) + '-shipinhao-'+str(log_type)+'.log'
 
         # 日志不打印到控制台
         logger.remove(handler_id=None)

+ 3 - 0
xinshi/__init__.py

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

+ 37 - 0
xinshi/demo.py

@@ -0,0 +1,37 @@
+# -*- coding: utf-8 -*-
+# @Author: wangkun
+# @Time: 2022/10/25
+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)
+
+
+if __name__ == '__main__':
+    Demo.get_hotword()

+ 468 - 0
xinshi/xinshi_app.py

@@ -0,0 +1,468 @@
+# -*- coding: utf-8 -*-
+# @Author: wangkun
+# @Time: 2022/10/26
+import os
+import sys
+import time
+from appium import webdriver
+from appium.webdriver.extensions.android.nativekey import AndroidKey
+from appium.webdriver.webdriver import WebDriver
+from selenium.common import NoSuchElementException
+from selenium.webdriver.common.by import By
+
+from xinshi.xinshi_publish import Publish
+
+sys.path.append(os.getcwd())
+from main.common import Common
+from main.feishu_lib import Feishu
+
+
+class XinshiAPP:
+    i = 0
+
+    @classmethod
+    def start_wechat(cls, log_type, env):
+        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')
+
+    @classmethod
+    def search_element(cls, log_type, driver: WebDriver, element):
+        try:
+            windowHandles = driver.window_handles
+            # 遍历所有的handles,找到当前页面所在的handle:如果pageSource有包含你想要的元素,就是所要找的handle
+            # 小程序的页面来回切换也需要:遍历所有的handles,切换到元素所在的handle
+            for handle in windowHandles:
+                driver.switch_to.window(handle)
+                time.sleep(3)
+                if len(driver.find_elements(By.XPATH, element)) != 0:
+                    return driver.find_element(By.XPATH, element)
+                else:
+                    pass
+        except Exception as e:
+            Common.logger(log_type).warning('search_element异常:{}\n', e)
+
+    @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)
+
+                    if video_title[:20] in download_title and video_user in download_user:
+                        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)
+
+    @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)
+            else:
+                Common.logger(log_type).info('URL 信息已更新\n')
+                break
+
+    @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)
+                        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://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 == '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)
+                        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__':
+    XinshiAPP.start_wechat('xinshi-app', 'dev')
+
+    pass

+ 192 - 0
xinshi/xinshi_pc.py

@@ -0,0 +1,192 @@
+# -*- coding: utf-8 -*-
+# @Author: wangkun
+# @Time: 2022/10/25
+import os
+import sys
+import time
+from selenium.common import NoSuchElementException
+from selenium.webdriver import DesiredCapabilities, ActionChains
+from selenium.webdriver.common.by import By
+from seleniumwire import webdriver
+sys.path.append(os.getcwd())
+from main.common import Common
+from main.feishu_lib import Feishu
+
+
+class XinshiPC:
+    @classmethod
+    def login(cls, log_type):
+        # 打印请求配置
+        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")
+
+        # driver初始化
+        # Common.logger(log_type).info('初始化 webdriver')
+        driver = webdriver.Chrome(desired_capabilities=ca)
+        # driver = webdriver.Chrome(desired_capabilities=ca, options=chrome_options)
+
+        driver.implicitly_wait(10)
+        Common.logger(log_type).info('打开网页"新视-热门内容"')
+        driver.get('https://xs.newrank.cn/Material/faddish/recentHot')
+        driver.maximize_window()
+        driver.implicitly_wait(10)
+
+        time.sleep(1)
+        Common.logger(log_type).info('点击"登录/按钮"')
+        driver.find_element(By.XPATH, '//button[@class="ant-btn ant-btn-primary"]').click()
+
+        time.sleep(1)
+        Common.logger(log_type).info('点击"其他登录方式"')
+        driver.find_element(By.XPATH, '//span[@class ="_2XRFN1F6"]').click()
+
+        time.sleep(1)
+        Common.logger(log_type).info('输入手机号')
+        driver.find_element(By.XPATH, '//input[@class="_2DyE0cvF"]').send_keys('13426262515')
+        Common.logger(log_type).info('输入密码')
+        driver.find_element(By.XPATH, '//input[@placeholder="输入密码"]').send_keys('test111111')
+
+        time.sleep(1)
+        Common.logger(log_type).info('勾选"保持登录状态"')
+        driver.find_element(By.XPATH, '//input[@class="nrd-login-checkbox-input"]').click()
+        time.sleep(1)
+        Common.logger(log_type).info('点击"登录"')
+        driver.find_element(By.XPATH, '//button[@class="_3RtjFeM- _CH1sF8Xz _38DPDVRd"]').click()
+
+        # 滑块
+        try:
+            slider = driver.find_element(By.XPATH, '//span[@class="nc_iconfont btn_slide"]')
+            slider_full = driver.find_element(By.XPATH, '//div[@class="scale_text slidetounlock"]')
+            Common.logger(log_type).info('拖动滑块')
+            time.sleep(1)
+            """
+            解决特征识别的代码
+            script = 'Object.defineProperty(navigator, "webdriver", {get: () => false,});'
+            driver.execute_script(script)
+            如果不采取去除特征识别,即以下两行代码。则页面的滑块验证码在滑动后,会显示如下图的出错,从而阻止登录进行。
+            因为服务器识别到的selenium的特征。使用该两行代码更改了特征,即可以顺利通过识别。
+            一般是反爬虫机制,用selenium打开的浏览器,就算手动去滑动都不行。
+            """
+            script = 'Object.defineProperty(navigator, "webdriver", {get: () => false,});'
+            driver.execute_script(script)
+            ActionChains(driver).drag_and_drop_by_offset(
+                slider, slider_full.size['width'], -slider.size['height']).perform()
+        except NoSuchElementException:
+            Common.logger(log_type).info('没有滑块')
+            pass
+
+        # 登录成功,获取到头像
+        time.sleep(3)
+        try:
+            driver.find_element(By.XPATH, '//img[@class="_J1BGEmMJ"]')
+            Common.logger(log_type).info('登录成功\n')
+        except NoSuchElementException:
+            Common.logger(log_type).info('登录失败,重新登录\n')
+            driver.quit()
+            cls.login(log_type)
+
+        # 获取热门内容
+        cls.get_recenhot(log_type, driver)
+        Common.logger(log_type).info('新视-热门内容抓取完毕\n')
+
+        # 获取十万推荐内容
+        cls.get_hundredthousand(log_type, driver)
+        Common.logger(log_type).info('新视-十万推荐内容抓取完毕\n')
+
+        time.sleep(5)
+        Common.logger(log_type).info('退出浏览器\n')
+        driver.close()
+        driver.quit()
+
+    @classmethod
+    def get_recenhot(cls, log_type, driver):
+        time.sleep(3)
+        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', '')
+            user_name = driver.find_element(
+                By.XPATH, '//div[@class="_6gxA3h-x"]/*[' + str(i) + ']//div[@class="_zoylmQ8m"]'
+            ).get_attribute('title').replace('\n', '')
+
+            Common.logger(log_type).info(video_title)
+            Common.logger(log_type).info(user_name)
+
+            if video_title == '':
+                Common.logger(log_type).info('无标题\n')
+            elif video_title in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'c77cf9') for x in y]:
+                Common.logger(log_type).info('视频已下载\n')
+            elif video_title in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'WAG7Dq') for x in y]:
+                Common.logger(log_type).info('视频已下载\n')
+            elif video_title in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', '0i4jmV') for x in y]:
+                Common.logger(log_type).info('视频已下载\n')
+            elif video_title in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'gO4Sn4') for x in y]:
+                Common.logger(log_type).info('视频已存在\n')
+            else:
+                Feishu.insert_columns(log_type, 'shipinhao', 'gO4Sn4', 'ROWS', 1, 2)
+                # 看一看云文档,工作表中写入数据
+                values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(time.time()))),
+                           '新视-热门榜',
+                           video_title,
+                           user_name]]
+                time.sleep(1)
+                Feishu.update_values(log_type, 'shipinhao', 'gO4Sn4', 'A2:Z2', values)
+                Common.logger(log_type).info('视频信息写入飞书成功\n')
+
+    @classmethod
+    def get_hundredthousand(cls, log_type, driver):
+        time.sleep(3)
+        Common.logger(log_type).info('点击"十万推荐"')
+        driver.find_element(By.XPATH, '//div[@class="ant-tabs-nav-list"]/*[2]').click()
+        time.sleep(3)
+        Common.logger(log_type).info('滚动到页面底部')
+        for i in range(5):
+            Common.logger(log_type).info('向上滑动页面')
+            driver.execute_script("window.scrollBy(0, 3000)")
+            time.sleep(1)
+
+        time.sleep(5)
+        for i in range(1, 51):
+            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', '')
+            user_name = driver.find_element(
+                By.XPATH, '//div[@class="_tCg-GF3J"]/*['+str(i)+']//div[@class="_gD23uy8R"]'
+            ).get_attribute('title').replace('\n', '')
+
+            Common.logger(log_type).info(video_title)
+            Common.logger(log_type).info(user_name)
+
+            if video_title == '':
+                Common.logger(log_type).info('无标题\n')
+            elif video_title in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'c77cf9') for x in y]:
+                Common.logger(log_type).info('视频已下载\n')
+            elif video_title in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'WAG7Dq') for x in y]:
+                Common.logger(log_type).info('视频已下载\n')
+            elif video_title in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', '0i4jmV') for x in y]:
+                Common.logger(log_type).info('视频已下载\n')
+            elif video_title in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'aOjaIU') for x in y]:
+                Common.logger(log_type).info('视频已存在\n')
+            else:
+                Feishu.insert_columns(log_type, 'shipinhao', 'aOjaIU', 'ROWS', 1, 2)
+                # 看一看云文档,工作表中写入数据
+                values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(time.time()))),
+                           '新视-推荐榜',
+                           video_title,
+                           user_name]]
+                time.sleep(1)
+                Feishu.update_values(log_type, 'shipinhao', 'aOjaIU', 'A2:Z2', values)
+                Common.logger(log_type).info('视频信息写入飞书成功\n')
+
+
+if __name__ == '__main__':
+    XinshiPC.login('xinshi-hot')
+
+    pass

+ 260 - 0
xinshi/xinshi_publish.py

@@ -0,0 +1,260 @@
+# -*- coding: utf-8 -*-
+# @Author: wangkun
+# @Time: 2022/10/27
+"""
+上传视频到阿里云 OSS
+上传视频到管理后台
+"""
+import json
+import os
+import random
+import shutil
+import time
+import oss2
+import requests
+import urllib3
+from main.common import Common
+proxies = {"http": None, "https": None}
+
+
+class Publish:
+    @classmethod
+    def publish_video_dev(cls, log_type, request_data):
+        """
+        loginUid  站内uid (随机)
+        appType  默认:888888
+        crawlerSrcId   站外视频ID
+        crawlerSrcCode   渠道(自定义 KYK)
+        crawlerSrcPublishTimestamp  视频原发布时间
+        crawlerTaskTimestamp   爬虫创建时间(可以是当前时间)
+        videoPath  视频oss地址
+        coverImgPath  视频封面oss地址
+        title  标题
+        totalTime  视频时长
+        viewStatus  视频的有效状态 默认1
+        versionCode  版本 默认1
+        :return:
+        """
+        # Common.logger().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"]
+        # Common.logger(log_type).info('video_id: {}'.format(video_id))
+        if result['code'] != 0:
+            Common.logger(log_type).error('pushlish failure msg = {}'.format(result['msg']))
+        else:
+            Common.logger(log_type).info('publish success video_id = : {}'.format(request_data['crawlerSrcId']))
+        return video_id
+
+    @classmethod
+    def publish_video_prod(cls, log_type, request_data):
+        """
+        loginUid  站内uid (随机)
+        appType  默认:888888
+        crawlerSrcId   站外视频ID
+        crawlerSrcCode   渠道(自定义 KYK)
+        crawlerSrcPublishTimestamp  视频原发布时间
+        crawlerTaskTimestamp   爬虫创建时间(可以是当前时间)
+        videoPath  视频oss地址
+        coverImgPath  视频封面oss地址
+        title  标题
+        totalTime  视频时长
+        viewStatus  视频的有效状态 默认1
+        versionCode  版本 默认1
+        :return:
+        """
+        result = cls.request_post('https://longvideoapi.piaoquantv.com/longvideoapi/crawler/video/send', request_data)
+        # Common.logger(log_type).info('publish result: {}'.format(result))
+        video_id = result["data"]["id"]
+        # Common.logger(log_type).info('video_id: {}'.format(video_id))
+        if result['code'] != 0:
+            Common.logger(log_type).error('pushlish failure msg = {}'.format(result['msg']))
+        else:
+            Common.logger(log_type).info('publish success video_id = : {}'.format(request_data['crawlerSrcId']))
+        return video_id
+
+    @classmethod
+    def request_post(cls, request_url, request_data):
+        """
+        post 请求 HTTP接口
+        :param request_url: 接口URL
+        :param request_data: 请求参数
+        :return: res_data json格式
+        """
+        urllib3.disable_warnings()
+        response = requests.post(url=request_url, data=request_data, proxies=proxies, verify=False)
+        if response.status_code == 200:
+            res_data = json.loads(response.text)
+            return res_data
+
+    # 以下代码展示了基本的文件上传、下载、罗列、删除用法。
+
+    # 首先初始化AccessKeyId、AccessKeySecret、Endpoint等信息。
+    # 通过环境变量获取,或者把诸如“<你的AccessKeyId>”替换成真实的AccessKeyId等。
+    #
+    # 以杭州区域为例,Endpoint可以是:
+    #   http://oss-cn-hangzhou.aliyuncs.com
+    #   https://oss-cn-hangzhou.aliyuncs.com
+    # 分别以HTTP、HTTPS协议访问。
+    access_key_id = os.getenv('OSS_TEST_ACCESS_KEY_ID', 'LTAIP6x1l3DXfSxm')
+    access_key_secret = os.getenv('OSS_TEST_ACCESS_KEY_SECRET', 'KbTaM9ars4OX3PMS6Xm7rtxGr1FLon')
+    bucket_name = os.getenv('OSS_TEST_BUCKET', 'art-pubbucket')
+    # endpoint = os.getenv('OSS_TEST_ENDPOINT', 'oss-cn-hangzhou-internal.aliyuncs.com')
+    endpoint = os.getenv('OSS_TEST_ENDPOINT', 'oss-cn-hangzhou.aliyuncs.com')
+
+    # 确认上面的参数都填写正确了
+    for param in (access_key_id, access_key_secret, bucket_name, endpoint):
+        assert '<' not in param, '请设置参数:' + param
+
+    # 创建Bucket对象,所有Object相关的接口都可以通过Bucket对象来进行
+    bucket = oss2.Bucket(oss2.Auth(access_key_id, access_key_secret), endpoint, bucket_name)
+
+    """
+    处理流程:
+    1. 定时(每天凌晨1点执行一次)循环files文件下的内容 结构:files -> 视频文件夹 -> 视频文件 + 封面图 + 基本信息
+    2. 视频文件和封面上传到oss
+    - 视频文件oss目录  longvideo/crawler_local/video/prod/文件名
+    - 视频封面oss目录  longvideo/crawler_local/image/prod/文件名
+    3. 发布视频
+    - 读取 基本信息 调用发布接口
+    """
+    # env 日期20220225 文件名
+    oss_file_path_video = 'longvideo/crawler_local/video/{}/{}/{}'
+    oss_file_path_image = 'longvideo/crawler_local/image/{}/{}/{}'
+
+    @classmethod
+    def put_file(cls, log_type, oss_file, local_file):
+        cls.bucket.put_object_from_file(oss_file, local_file)
+        Common.logger(log_type).info("put oss file = {}, local file = {} success".format(oss_file, local_file))
+
+    # 清除本地文件
+    @classmethod
+    def remove_local_file(cls, log_type, local_file):
+        os.remove(local_file)
+        Common.logger(log_type).info("remove local file = {} success".format(local_file))
+
+    # 清除本地文件夹
+    @classmethod
+    def remove_local_file_dir(cls, log_type, local_file):
+        os.rmdir(local_file)
+        Common.logger(log_type).info("remove local file dir = {} success".format(local_file))
+
+    local_file_path = './videos'
+    video_file = 'video'
+    image_file = 'image'
+    info_file = 'info'
+    uids_dev_up = [6267140]
+    uids_dev_play = [6267141]
+    uids_prod_xinshi_hot = [26117438]
+    uids_prod_xinshi_recommend = [26117439]
+
+    @classmethod
+    def upload_and_publish(cls, log_type, env, job):
+        """
+        上传视频到 oss
+        :param log_type: 选择的 log
+        :param env: 测试环境:dev,正式环境:prod
+        :param job: 上升榜:up,播放量:play
+        """
+        Common.logger(log_type).info("upload_and_publish starting...")
+        today = time.strftime("%Y%m%d", time.localtime())
+        # videos 目录下的所有视频文件夹
+        files = os.listdir(cls.local_file_path)
+        for f in files:
+            try:
+                # 单个视频文件夹
+                fi_d = os.path.join(cls.local_file_path, f)
+                # 确认为视频文件夹
+                if os.path.isdir(fi_d):
+                    Common.logger(log_type).info('dir = {}'.format(fi_d))
+                    # 列出所有视频文件夹
+                    dir_files = os.listdir(fi_d)
+                    data = {'appType': '888888',
+                            'crawlerSrcCode': 'SHIPINHAO_XCX',
+                            'viewStatus': '1',
+                            'versionCode': '1'}
+                    now_timestamp = int(round(time.time() * 1000))
+                    data['crawlerTaskTimestamp'] = str(now_timestamp)
+                    global uid
+                    if env == "dev" and job == "xinshi_hot":
+                        uid = str(random.choice(cls.uids_dev_up))
+                    elif env == "dev" and job == "xinshi_recommend":
+                        uid = str(random.choice(cls.uids_dev_play))
+                    elif env == "prod" and job == "xinshi_hot":
+                        uid = str(random.choice(cls.uids_prod_xinshi_hot))
+                    elif env == "prod" and job == "xinshi_recommend":
+                        uid = str(random.choice(cls.uids_prod_xinshi_recommend))
+                    data['loginUid'] = uid
+                    # 单个视频文件夹下的所有视频文件
+                    for fi in dir_files:
+                        # 视频文件夹下的所有文件路径
+                        fi_path = fi_d + '/' + fi
+                        Common.logger(log_type).info('dir fi_path = {}'.format(fi_path))
+                        # 读取 info.txt,赋值给 data
+                        if cls.info_file in fi:
+                            f = open(fi_path, "r", encoding="UTF-8")
+                            # 读取数据 数据准确性写入的时候保证 读取暂不处理
+                            for i in range(14):
+                                line = f.readline()
+                                line = line.replace('\n', '')
+                                if line is not None and len(line) != 0 and not line.isspace():
+                                    # Common.logger(log_type).info("line = {}".format(line))
+                                    if i == 0:
+                                        data['crawlerSrcId'] = line
+                                    elif i == 1:
+                                        data['title'] = line
+                                    elif i == 2:
+                                        data['totalTime'] = line
+                                    elif i == 8:
+                                        data['crawlerSrcPublishTimestamp'] = line
+                                else:
+                                    Common.logger(log_type).warning("{} line is None".format(fi_path))
+                            f.close()
+                            # remove info.txt
+                            cls.remove_local_file(log_type, fi_path)
+                    # 刷新数据
+                    dir_files = os.listdir(fi_d)
+                    for fi in dir_files:
+                        fi_path = fi_d + '/' + fi
+                        # Common.logger(log_type).info('dir fi_path = {}'.format(fi_path))
+                        # 上传oss
+                        if cls.video_file in fi:
+                            global oss_video_file
+                            if env == "dev":
+                                oss_video_file = cls.oss_file_path_video.format("dev", today, data['crawlerSrcId'])
+                            elif env == "prod":
+                                oss_video_file = cls.oss_file_path_video.format("prod", today, data['crawlerSrcId'])
+                            Common.logger(log_type).info("oss_video_file = {}".format(oss_video_file))
+                            cls.put_file(log_type, oss_video_file, fi_path)
+                            data['videoPath'] = oss_video_file
+                            Common.logger(log_type).info("videoPath = {}".format(oss_video_file))
+                        elif cls.image_file in fi:
+                            global oss_image_file
+                            if env == "dev":
+                                oss_image_file = cls.oss_file_path_image.format("env", today, data['crawlerSrcId'])
+                            elif env == "prod":
+                                oss_image_file = cls.oss_file_path_image.format("prod", today, data['crawlerSrcId'])
+                            Common.logger(log_type).info("oss_image_file = {}".format(oss_image_file))
+                            cls.put_file(log_type, oss_image_file, fi_path)
+                            data['coverImgPath'] = oss_image_file
+                            Common.logger(log_type).info("coverImgPath = {}".format(oss_image_file))
+                        # 全部remove
+                        cls.remove_local_file(log_type, fi_path)
+
+                    # 发布
+                    if env == "dev":
+                        video_id = cls.publish_video_dev(log_type, data)
+                    elif env == "prod":
+                        video_id = cls.publish_video_prod(log_type, data)
+                    else:
+                        video_id = cls.publish_video_dev(log_type, data)
+                    cls.remove_local_file_dir(log_type, fi_d)
+                    Common.logger(log_type).info('video_id:{}', video_id)
+                    return video_id
+
+                else:
+                    Common.logger(log_type).error('file not a dir = {}'.format(fi_d))
+            except Exception as e:
+                # 删除视频文件夹
+                shutil.rmtree("./videos/" + f + "/")
+                Common.logger(log_type).exception('upload_and_publish error', e)

+ 170 - 0
xinshi/xinshi_windows.py

@@ -0,0 +1,170 @@
+# -*- coding: utf-8 -*-
+# @Author: wangkun
+# @Time: 2022/10/26
+import json
+import os
+import sys
+import time
+import psutil
+from appium import webdriver
+from selenium.webdriver.common.by import By
+sys.path.append(os.getcwd())
+from main.common import Common
+from main.feishu_lib import Feishu
+
+
+class GetXinshiGetUrl:
+    @classmethod
+    def kill_pid(cls, log_type):
+        try:
+            os.system('chcp 65001')  # 将cmd的显示字符编码从默认的GBK改为UTF-8
+            list_process = list()
+            pid_list = psutil.pids()
+            for sub_pid in pid_list:
+                try:
+                    process_info = psutil.Process(sub_pid)
+                    if process_info.name() == 'WechatBrowser.exe' or process_info.name() == 'WeChatPlayer.exe':
+                        list_process.append(sub_pid)
+                except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
+                    pass
+            for pid in list_process:
+                os.system('taskkill /f /pid ' + str(pid))
+        except Exception as e:
+            Common.logger(log_type).error('kill_pid异常:{}', e)
+
+    @classmethod
+    def click_video(cls, log_type):
+        try:
+            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('点击"爬虫群"')
+            # driver.find_elements(By.NAME, '爬虫群')[0].click()
+
+            Common.logger(log_type).info('点击视频')
+            driver.find_elements(By.NAME, '消息')[-1].click()
+
+            Common.logger(log_type).info('休眠 10 秒,退出视频号')
+            time.sleep(10)
+            cls.kill_pid(log_type)
+
+            Common.logger(log_type).info('退出微信')
+            driver.quit()
+        except Exception as e:
+            Common.logger(log_type).error('click_video异常:{}', e)
+
+    @classmethod
+    def get_url(cls, log_type):
+        try:
+            # charles 抓包文件保存目录
+            charles_file_dir = r"./chlsfiles/"
+
+            if len(os.listdir(charles_file_dir)) == 0:
+                Common.logger(log_type).info("未找到chlsfile文件,等待2s")
+                time.sleep(2)
+            else:
+                # 目标文件夹下所有文件
+                all_file = sorted(os.listdir(charles_file_dir))
+
+                # 获取到目标文件
+                old_file = all_file[-1]
+
+                # 分离文件名与扩展名
+                new_file = os.path.splitext(old_file)
+
+                # 重命名文件后缀
+                os.rename(os.path.join(charles_file_dir, old_file),
+                          os.path.join(charles_file_dir, new_file[0] + ".txt"))
+
+                with open(charles_file_dir + new_file[0] + ".txt", encoding='utf-8-sig', errors='ignore') as f:
+                    contents = json.load(f, strict=False)
+
+                video_url_list = []
+                cover_url_list = []
+
+                if "finder.video.qq.com" in [text['host'] for text in contents]:
+                    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/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
+
+                    # print(f'video_url:{video_url}')
+                    # print(f'cover_url:{cover_url}')
+                    # print(f'head_url:{head_url}')
+
+                    return video_url, cover_url, head_url
+                else:
+                    Common.logger(log_type).info("未找到url")
+                    return '未找到url'
+
+        except Exception as e:
+            Common.logger(log_type).exception("get_url异常:{}\n", e)
+            return None
+
+    @classmethod
+    def write_url(cls, log_type, sheetid):
+        try:
+            while True:
+                if Feishu.get_values_batch(log_type, 'shipinhao', sheetid)[1][11] is None:
+                    Common.del_charles_files('recommend')
+                    cls.click_video(log_type)
+                    Common.logger(log_type).info('等待 2s')
+                    time.sleep(2)
+                    Common.logger(log_type).info('获取视频头像/封面/播放地址')
+                    urls = cls.get_url(log_type)
+                    if urls == '未找到url':
+                        time.sleep(1)
+                        cls.write_url(log_type, sheetid)
+                    elif urls is None:
+                        time.sleep(1)
+                        cls.write_url(log_type, sheetid)
+                    else:
+                        Feishu.update_values(log_type, 'shipinhao', sheetid, 'J2:L2',
+                                             [['https://' + urls[2], 'https://' + urls[1], 'https://' + urls[0]]])
+                        Common.logger(log_type).info('视频地址信息写入飞书成功\n')
+                        Common.del_charles_files('recommend')
+                        break
+                else:
+                    Common.logger(log_type).info('视频已有地址信息,休眠 10s')
+                    time.sleep(10)
+                    break
+        except Exception as e:
+            # Feishu.dimension_range(log_type, 'shipinhao', 'FSDlBy', 'ROWS', 2, 2)
+            Common.logger(log_type).error('write_url异常:{}\n', e)
+
+    @classmethod
+    def run_get_url(cls, log_type):
+        try:
+            while True:
+                if len(Feishu.get_values_batch(log_type, 'shipinhao', 'gO4Sn4')) > 1:
+                    cls.write_url(log_type, 'gO4Sn4')
+                elif len(Feishu.get_values_batch(log_type, 'shipinhao', 'aOjaIU')) > 1:
+                    cls.write_url(log_type, 'aOjaIU')
+                else:
+                    Common.logger(log_type).info('暂无需要获取地址的视频信息')
+                    time.sleep(30)
+                    break
+
+        except Exception as e:
+            Common.logger(log_type).error('run_get_url异常:{}\n', e)
+
+
+if __name__ == '__main__':
+    while True:
+        GetXinshiGetUrl.run_get_url('xinshi-get-url')
+        Common.del_logs('xinshi-get-url')
+        time.sleep(1)
+
+    pass