|
@@ -18,34 +18,36 @@ from main.common import Common
|
|
|
class GetUrl:
|
|
|
@classmethod
|
|
|
def click_video(cls, log_type, video_title):
|
|
|
- Common.logger(log_type).info('启动"微信"')
|
|
|
- desired_caps = {'app': r"C:\Program Files (x86)\Tencent\WeChat\WeChat.exe"}
|
|
|
- driver = webdriver.Remote(
|
|
|
- command_executor='http://127.0.0.1:4723',
|
|
|
- desired_capabilities=desired_caps)
|
|
|
- driver.implicitly_wait(10)
|
|
|
-
|
|
|
- Common.logger(log_type).info('点击"聊天窗口"')
|
|
|
- print('点击"聊天窗口"')
|
|
|
- driver.find_element(By.NAME, '聊天').click()
|
|
|
-
|
|
|
- Common.logger(log_type).info('点击"爬虫群"')
|
|
|
- print('点击"爬虫群"')
|
|
|
- driver.find_element(By.NAME, '爬虫群').click()
|
|
|
-
|
|
|
- Common.logger(log_type).info('点击视频:{}', video_title)
|
|
|
- print(f'点击视频{video_title}')
|
|
|
- driver.find_elements(By.ID, '42.852020.3.487')[-1].click()
|
|
|
- # driver.find_element(By.NAME, video_title[:10]).click()
|
|
|
- # els = driver.find_elements(By.TAG_NAME, '按钮')
|
|
|
- # print(len(els))
|
|
|
-
|
|
|
- time.sleep(5)
|
|
|
- print('退出')
|
|
|
- driver.quit()
|
|
|
-
|
|
|
- # windows = driver.window_handles
|
|
|
- # driver.switch_to.window(windows[0])
|
|
|
+ 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('点击"聊天窗口"')
|
|
|
+ # print('点击"聊天窗口"')
|
|
|
+ driver.find_element(By.NAME, '聊天').click()
|
|
|
+
|
|
|
+ Common.logger(log_type).info('点击"爬虫群"')
|
|
|
+ # print('点击"爬虫群"')
|
|
|
+ driver.find_element(By.NAME, '爬虫群').click()
|
|
|
+
|
|
|
+ Common.logger(log_type).info('点击视频:{}', video_title)
|
|
|
+ # print(f'点击视频{video_title}')
|
|
|
+ driver.find_elements(By.ID, '42.852020.3.487')[-1].click()
|
|
|
+
|
|
|
+ # 切换 windows 窗口
|
|
|
+ # windows = driver.window_handles
|
|
|
+ # driver.switch_to.window(windows[0])
|
|
|
+
|
|
|
+ Common.logger(log_type).info('休眠 3s 后,退出微信')
|
|
|
+ time.sleep(3)
|
|
|
+ driver.quit()
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ Common.logger(log_type).error('click_video异常:{}', e)
|
|
|
|
|
|
@classmethod
|
|
|
def get_url(cls, log_type):
|
|
@@ -88,9 +90,9 @@ class GetUrl:
|
|
|
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}')
|
|
|
+ # 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:
|
|
@@ -104,22 +106,45 @@ class GetUrl:
|
|
|
|
|
|
@classmethod
|
|
|
def write_url(cls, log_type):
|
|
|
- while True:
|
|
|
- if Feishu.get_values_batch(log_type, 'shipinhao', 'FSDlBy')[1][11] is None:
|
|
|
- # Common.logger(log_type).info('开始点击分享的视频')
|
|
|
- print(f"开始点击分享的视频:{Feishu.get_values_batch(log_type, 'shipinhao', 'FSDlBy')[1][2]}")
|
|
|
- cls.click_video(log_type, Feishu.get_values_batch(log_type, 'shipinhao', 'FSDlBy')[1][2])
|
|
|
- time.sleep(60)
|
|
|
- Common.logger(log_type).info('获取视频头像/封面/播放地址')
|
|
|
- print('获取视频头像/封面/播放地址')
|
|
|
- urls = cls.get_url(log_type)
|
|
|
- Feishu.update_values(log_type, 'shipinhao', 'FSDlBy', 'J2:L2',
|
|
|
- [['https://'+urls[2], 'https://'+urls[1], 'https://'+urls[0]]])
|
|
|
- Common.logger(log_type).info('视频地址信息写入飞书成功\n')
|
|
|
- break
|
|
|
- else:
|
|
|
- break
|
|
|
+ try:
|
|
|
+ while True:
|
|
|
+ if Feishu.get_values_batch(log_type, 'shipinhao', 'FSDlBy')[1][11] is None:
|
|
|
+ # Common.logger(log_type).info('开始点击分享的视频')
|
|
|
+ # print(f"开始点击分享的视频:{Feishu.get_values_batch(log_type, 'shipinhao', 'FSDlBy')[1][2]}")
|
|
|
+ cls.click_video(log_type, Feishu.get_values_batch(log_type, 'shipinhao', 'FSDlBy')[1][2])
|
|
|
+ Common.logger(log_type).info('等待 60s')
|
|
|
+ time.sleep(60)
|
|
|
+ Common.logger(log_type).info('获取视频头像/封面/播放地址')
|
|
|
+ # print('获取视频头像/封面/播放地址')
|
|
|
+ urls = cls.get_url(log_type)
|
|
|
+ Feishu.update_values(log_type, 'shipinhao', 'FSDlBy', 'J2:L2',
|
|
|
+ [['https://'+urls[2], 'https://'+urls[1], 'https://'+urls[0]]])
|
|
|
+ Common.logger(log_type).info('视频地址信息写入飞书成功\n')
|
|
|
+ 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异常,删除该视频记录:{}', e)
|
|
|
+
|
|
|
+ @classmethod
|
|
|
+ def run_get_url(cls, log_type):
|
|
|
+ try:
|
|
|
+ while True:
|
|
|
+ if len(Feishu.get_values_batch(log_type, 'shipinhao', 'FSDlBy')) == 1:
|
|
|
+ Common.logger(log_type).info('暂无需要获取地址的视频信息')
|
|
|
+ break
|
|
|
+ else:
|
|
|
+ cls.write_url(log_type)
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ Common.logger(log_type).error('run_get_url异常:{}', e)
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
- GetUrl.write_url('recommend')
|
|
|
+ # GetUrl.write_url('recommend')
|
|
|
+ # print(len(Feishu.get_values_batch('recommend', 'shipinhao', 'FSDlBy')))
|
|
|
+ while True:
|
|
|
+ GetUrl.run_get_url('recommend')
|