|
@@ -47,40 +47,43 @@ class Follow:
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
def start_follow_wechat(cls, log_type, user_name, env):
|
|
def start_follow_wechat(cls, log_type, user_name, 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
|
|
|
|
- "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',
|
|
|
|
- 'chromedriverExecutable': '/Users/lieyunye/Downloads/chromedriver_v86/chromedriver',
|
|
|
|
- }
|
|
|
|
- driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
|
|
|
|
- driver.implicitly_wait(10)
|
|
|
|
-
|
|
|
|
- cls.search_to_user_homepage(log_type, user_name, driver)
|
|
|
|
-
|
|
|
|
- cls.search_user_videos(log_type, driver, env)
|
|
|
|
-
|
|
|
|
- Common.logger(log_type).info('休眠 3s')
|
|
|
|
- time.sleep(3)
|
|
|
|
- cls.quit(log_type, driver)
|
|
|
|
|
|
+ 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
|
|
|
|
+ "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',
|
|
|
|
+ 'chromedriverExecutable': '/Users/lieyunye/Downloads/chromedriver_v86/chromedriver',
|
|
|
|
+ }
|
|
|
|
+ driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
|
|
|
|
+ driver.implicitly_wait(10)
|
|
|
|
+
|
|
|
|
+ cls.search_to_user_homepage(log_type, user_name, driver)
|
|
|
|
+
|
|
|
|
+ cls.search_user_videos(log_type, driver, env)
|
|
|
|
+
|
|
|
|
+ Common.logger(log_type).info('休眠 3s')
|
|
|
|
+ time.sleep(3)
|
|
|
|
+ cls.quit(log_type, driver)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ Common.logger(log_type).error(f'start_follow_wechat异常:{e}\n')
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
def quit(cls, log_type, driver: WebDriver):
|
|
def quit(cls, log_type, driver: WebDriver):
|
|
@@ -164,119 +167,123 @@ class Follow:
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
def get_video_info(cls, log_type, driver: WebDriver, env):
|
|
def get_video_info(cls, log_type, driver: WebDriver, env):
|
|
- driver.implicitly_wait(10)
|
|
|
|
- # 视频标题
|
|
|
|
- try:
|
|
|
|
- title_id = driver.find_element(By.ID, 'com.tencent.mm:id/ki5')
|
|
|
|
- video_title = title_id.get_attribute('name').split('\n')[0].strip()
|
|
|
|
- except NoSuchElementException:
|
|
|
|
- video_title = ''
|
|
|
|
-
|
|
|
|
- # 点击播放器,获取视频时长
|
|
|
|
- # 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:
|
|
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)
|
|
|
|
-
|
|
|
|
- # 用户名
|
|
|
|
- username_id = driver.find_element(By.ID, 'com.tencent.mm:id/hft')
|
|
|
|
- user_name = username_id.get_attribute('name')
|
|
|
|
-
|
|
|
|
- Common.logger(log_type).info('video_title:{}', video_title)
|
|
|
|
- Common.logger(log_type).info('duration:{}', duration)
|
|
|
|
- Common.logger(log_type).info('like_cnt:{}', like_cnt)
|
|
|
|
- Common.logger(log_type).info('share_cnt:{}', share_cnt)
|
|
|
|
- Common.logger(log_type).info('favorite_cnt:{}', favorite_cnt)
|
|
|
|
- Common.logger(log_type).info('comment_cnt:{}', comment_cnt)
|
|
|
|
- Common.logger(log_type).info('user_name:{}', user_name)
|
|
|
|
-
|
|
|
|
- if int(duration) < 50:
|
|
|
|
- Common.logger(log_type).info(f'时长:{int(duration)} < 50 秒\n')
|
|
|
|
- elif video_title == '':
|
|
|
|
- Common.logger(log_type).info('视频标题为空\n')
|
|
|
|
- # 过滤词库(视频标题)
|
|
|
|
- elif any(word if word in video_title else False for word in cls.filter_words(log_type)) is True:
|
|
|
|
- Common.logger(log_type).info(f'视频已中过滤词:{video_title}\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', 'KsVtLe') for x in y]:
|
|
|
|
- Common.logger(log_type).info('视频已下载\n')
|
|
|
|
- # feeds 表去重
|
|
|
|
- elif video_title in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'FSDlBy') for x in y]:
|
|
|
|
- Common.logger(log_type).info('视频已存在\n')
|
|
|
|
- # feeds 表去重
|
|
|
|
- elif video_title in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'qzDljJ') for x in y]:
|
|
|
|
- Common.logger(log_type).info('视频已存在\n')
|
|
|
|
- # 分享给 windows 爬虫机
|
|
|
|
- else:
|
|
|
|
- video_dict = {
|
|
|
|
- 'video_title': video_title,
|
|
|
|
- 'duration': duration,
|
|
|
|
- 'like_cnt': like_cnt,
|
|
|
|
- 'share_cnt': share_cnt,
|
|
|
|
- 'share_id': share_id,
|
|
|
|
- 'favorite_cnt': favorite_cnt,
|
|
|
|
- 'comment_cnt': comment_cnt,
|
|
|
|
- 'user_name': user_name
|
|
|
|
- }
|
|
|
|
- cls.share_to_windows(log_type, driver, video_dict, env)
|
|
|
|
|
|
+ driver.implicitly_wait(10)
|
|
|
|
+ # 视频标题
|
|
|
|
+ try:
|
|
|
|
+ title_id = driver.find_element(By.ID, 'com.tencent.mm:id/ki5')
|
|
|
|
+ video_title = title_id.get_attribute('name').split('\n')[0].strip()
|
|
|
|
+ except NoSuchElementException:
|
|
|
|
+ video_title = ''
|
|
|
|
+
|
|
|
|
+ # 点击播放器,获取视频时长
|
|
|
|
+ # 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)
|
|
|
|
+
|
|
|
|
+ # 用户名
|
|
|
|
+ username_id = driver.find_element(By.ID, 'com.tencent.mm:id/hft')
|
|
|
|
+ user_name = username_id.get_attribute('name')
|
|
|
|
+
|
|
|
|
+ Common.logger(log_type).info('video_title:{}', video_title)
|
|
|
|
+ Common.logger(log_type).info('duration:{}', duration)
|
|
|
|
+ Common.logger(log_type).info('like_cnt:{}', like_cnt)
|
|
|
|
+ Common.logger(log_type).info('share_cnt:{}', share_cnt)
|
|
|
|
+ Common.logger(log_type).info('favorite_cnt:{}', favorite_cnt)
|
|
|
|
+ Common.logger(log_type).info('comment_cnt:{}', comment_cnt)
|
|
|
|
+ Common.logger(log_type).info('user_name:{}', user_name)
|
|
|
|
+
|
|
|
|
+ if int(duration) < 50:
|
|
|
|
+ Common.logger(log_type).info(f'时长:{int(duration)} < 50 秒\n')
|
|
|
|
+ elif video_title == '':
|
|
|
|
+ Common.logger(log_type).info('视频标题为空\n')
|
|
|
|
+ # 过滤词库(视频标题)
|
|
|
|
+ elif any(word if word in video_title else False for word in cls.filter_words(log_type)) is True:
|
|
|
|
+ Common.logger(log_type).info(f'视频已中过滤词:{video_title}\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', 'KsVtLe') for x in y]:
|
|
|
|
+ Common.logger(log_type).info('视频已下载\n')
|
|
|
|
+ # feeds 表去重
|
|
|
|
+ elif video_title in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'FSDlBy') for x in y]:
|
|
|
|
+ Common.logger(log_type).info('视频已存在\n')
|
|
|
|
+ # feeds 表去重
|
|
|
|
+ elif video_title in [x for y in Feishu.get_values_batch(log_type, 'shipinhao', 'qzDljJ') for x in y]:
|
|
|
|
+ Common.logger(log_type).info('视频已存在\n')
|
|
|
|
+ # 分享给 windows 爬虫机
|
|
|
|
+ else:
|
|
|
|
+ video_dict = {
|
|
|
|
+ 'video_title': video_title,
|
|
|
|
+ 'duration': duration,
|
|
|
|
+ 'like_cnt': like_cnt,
|
|
|
|
+ 'share_cnt': share_cnt,
|
|
|
|
+ 'share_id': share_id,
|
|
|
|
+ 'favorite_cnt': favorite_cnt,
|
|
|
|
+ 'comment_cnt': comment_cnt,
|
|
|
|
+ 'user_name': user_name
|
|
|
|
+ }
|
|
|
|
+ cls.share_to_windows(log_type, driver, video_dict, env)
|
|
|
|
+
|
|
|
|
+ except Exception as e:
|
|
|
|
+ Common.logger(log_type).error(f'get_video_info异常:{e}\n')
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
def share_to_windows(cls, log_type, driver: WebDriver, video_dict, env):
|
|
def share_to_windows(cls, log_type, driver: WebDriver, video_dict, env):
|