|
@@ -49,73 +49,73 @@ class ZhiqingtiantiankanRecommend:
|
|
|
|
|
|
@classmethod
|
|
|
def start_wechat(cls, log_type, crawler, env):
|
|
|
- try:
|
|
|
- Common.logger(log_type, crawler).info('启动微信')
|
|
|
- if env == "dev":
|
|
|
- chromedriverExecutable = '/Users/wangkun/Downloads/chromedriver/chromedriver_v107/chromedriver'
|
|
|
- else:
|
|
|
- # chromedriverExecutable = '/Users/piaoquan/Downloads/chromedriver' # Mac 爬虫机器
|
|
|
- chromedriverExecutable = 'C:\\chromedriver\\chromedriver.exe' # 阿里云 Windows
|
|
|
- caps = {
|
|
|
- "platformName": "Android", # 手机操作系统 Android / iOS
|
|
|
- "deviceName": "Android", # 连接的设备名(模拟器或真机),安卓可以随便写
|
|
|
- "udid": "emulator-5554", # 指定 adb devices 中的哪一台设备
|
|
|
- "platforVersion": "12", # 手机对应的系统版本
|
|
|
- "appPackage": "com.tencent.mm", # 被测APP的包名
|
|
|
- "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,
|
|
|
- 'enableWebviewDetailsCollection': True,
|
|
|
- 'setWebContentsDebuggingEnabled': True,
|
|
|
- 'recreateChromeDriverSessions': True,
|
|
|
- 'chromedriverExecutable': chromedriverExecutable,
|
|
|
- "chromeOptions": {"androidProcess": "com.tencent.mm:appbrand0"},
|
|
|
- # "chromeOptions": {"androidProcess": "com.tencent.mm:tools"},
|
|
|
- 'browserName': ''
|
|
|
- }
|
|
|
- driver = webdriver.Remote("http://localhost:4723/wd/hub", caps) # 指定 Appium 端口号:4723
|
|
|
- driver.implicitly_wait(30)
|
|
|
- # 向下滑动页面,展示出小程序选择面板
|
|
|
- for i in range(120):
|
|
|
- try:
|
|
|
- # 发现微信消息 TAB,代表微信已启动成功
|
|
|
- if driver.find_elements(By.ID, 'com.tencent.mm:id/f2s'):
|
|
|
- break
|
|
|
- # 发现并关闭系统菜单栏
|
|
|
- elif driver.find_element(By.ID, 'com.android.systemui:id/dismiss_view'):
|
|
|
- Common.logger(log_type, crawler).info('发现并关闭系统下拉菜单栏')
|
|
|
- driver.find_element(By.ID, 'com.android.systemui:id/dismiss_view').click()
|
|
|
- else:
|
|
|
- pass
|
|
|
- except NoSuchElementException:
|
|
|
- time.sleep(1)
|
|
|
- Common.logger(log_type, crawler).info('下滑,展示小程序选择面板')
|
|
|
- size = driver.get_window_size()
|
|
|
- driver.swipe(int(size['width'] * 0.5), int(size['height'] * 0.2), int(size['width'] * 0.5),
|
|
|
- int(size['height'] * 0.8), 200)
|
|
|
- # 打开小程序"知青天天看"
|
|
|
- time.sleep(5)
|
|
|
- Common.logger(log_type, crawler).info('打开小程序"知青天天看"')
|
|
|
- driver.find_elements(By.XPATH, '//*[@text="知青天天看"]')[-1].click()
|
|
|
-
|
|
|
- # 获取视频信息
|
|
|
- time.sleep(10)
|
|
|
- cls.get_videoList(log_type, crawler, driver, env)
|
|
|
-
|
|
|
- # 退出微信
|
|
|
- cls.quit(log_type, crawler, driver)
|
|
|
- except Exception as e:
|
|
|
- Common.logger(log_type, crawler).error('start_wechat异常:{}\n', e)
|
|
|
- cmd = "adb kill-server && adb start-server"
|
|
|
- os.system(cmd)
|
|
|
+ # try:
|
|
|
+ Common.logger(log_type, crawler).info('启动微信')
|
|
|
+ if env == "dev":
|
|
|
+ chromedriverExecutable = '/Users/wangkun/Downloads/chromedriver/chromedriver_v107/chromedriver'
|
|
|
+ else:
|
|
|
+ # chromedriverExecutable = '/Users/piaoquan/Downloads/chromedriver' # Mac 爬虫机器
|
|
|
+ chromedriverExecutable = 'C:\\chromedriver\\chromedriver.exe' # 阿里云 Windows
|
|
|
+ caps = {
|
|
|
+ "platformName": "Android", # 手机操作系统 Android / iOS
|
|
|
+ "deviceName": "Android", # 连接的设备名(模拟器或真机),安卓可以随便写
|
|
|
+ "udid": "emulator-5554", # 指定 adb devices 中的哪一台设备
|
|
|
+ "platforVersion": "12", # 手机对应的系统版本
|
|
|
+ "appPackage": "com.tencent.mm", # 被测APP的包名
|
|
|
+ "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,
|
|
|
+ 'enableWebviewDetailsCollection': True,
|
|
|
+ 'setWebContentsDebuggingEnabled': True,
|
|
|
+ 'recreateChromeDriverSessions': True,
|
|
|
+ 'chromedriverExecutable': chromedriverExecutable,
|
|
|
+ "chromeOptions": {"androidProcess": "com.tencent.mm:appbrand0"},
|
|
|
+ # "chromeOptions": {"androidProcess": "com.tencent.mm:tools"},
|
|
|
+ 'browserName': ''
|
|
|
+ }
|
|
|
+ driver = webdriver.Remote("http://localhost:4723/wd/hub", caps) # 指定 Appium 端口号:4723
|
|
|
+ driver.implicitly_wait(30)
|
|
|
+ # 向下滑动页面,展示出小程序选择面板
|
|
|
+ for i in range(120):
|
|
|
+ try:
|
|
|
+ # 发现微信消息 TAB,代表微信已启动成功
|
|
|
+ if driver.find_elements(By.ID, 'com.tencent.mm:id/f2s'):
|
|
|
+ break
|
|
|
+ # 发现并关闭系统菜单栏
|
|
|
+ elif driver.find_element(By.ID, 'com.android.systemui:id/dismiss_view'):
|
|
|
+ Common.logger(log_type, crawler).info('发现并关闭系统下拉菜单栏')
|
|
|
+ driver.find_element(By.ID, 'com.android.systemui:id/dismiss_view').click()
|
|
|
+ else:
|
|
|
+ pass
|
|
|
+ except NoSuchElementException:
|
|
|
+ time.sleep(1)
|
|
|
+ Common.logger(log_type, crawler).info('下滑,展示小程序选择面板')
|
|
|
+ size = driver.get_window_size()
|
|
|
+ driver.swipe(int(size['width'] * 0.5), int(size['height'] * 0.2), int(size['width'] * 0.5),
|
|
|
+ int(size['height'] * 0.8), 200)
|
|
|
+ # 打开小程序"知青天天看"
|
|
|
+ time.sleep(5)
|
|
|
+ Common.logger(log_type, crawler).info('打开小程序"知青天天看"')
|
|
|
+ driver.find_elements(By.XPATH, '//*[@text="知青天天看"]')[-1].click()
|
|
|
+
|
|
|
+ # 获取视频信息
|
|
|
+ time.sleep(10)
|
|
|
+ cls.get_videoList(log_type, crawler, driver, env)
|
|
|
+
|
|
|
+ # 退出微信
|
|
|
+ cls.quit(log_type, crawler, driver)
|
|
|
+ # except Exception as e:
|
|
|
+ # Common.logger(log_type, crawler).error('start_wechat异常:{}\n', e)
|
|
|
+ # cmd = "adb kill-server && adb start-server"
|
|
|
+ # os.system(cmd)
|
|
|
|
|
|
# 退出 APP
|
|
|
@classmethod
|