wangkun 1 năm trước cách đây
mục cha
commit
976167acb3

+ 59 - 59
zhongmiaoyinxin/zhongmiaoyinxin_recommend/zhongmiaoyinxin_recommend.py

@@ -49,67 +49,67 @@ class ZhongmiaoyinxinRecommend:
 
     @classmethod
     def start_wechat(cls, log_type, crawler, env):
-        try:
-            if env == "dev":
-                chromedriverExecutable = "/Users/wangkun/Downloads/chromedriver/chromedriver_v107/chromedriver"
-            else:
-                chromedriverExecutable = '/Users/piaoquan/Downloads/chromedriver'
-            Common.logger(log_type, crawler).info('启动微信')
-            caps = {
-                "platformName": "Android",  # 手机操作系统 Android / iOS
-                "deviceName": "a0a65126",  # 连接的设备名(模拟器或真机),安卓可以随便写
-                "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,
-                '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)
-            driver.implicitly_wait(20)
-            # 向下滑动页面,展示出小程序选择面板
-            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()
+        # try:
+        if env == "dev":
+            chromedriverExecutable = "/Users/wangkun/Downloads/chromedriver/chromedriver_v107/chromedriver"
+        else:
+            chromedriverExecutable = '/Users/piaoquan/Downloads/chromedriver'
+        Common.logger(log_type, crawler).info('启动微信')
+        caps = {
+            "platformName": "Android",  # 手机操作系统 Android / iOS
+            "deviceName": "a0a65126",  # 连接的设备名(模拟器或真机),安卓可以随便写
+            "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,
+            '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)
+        driver.implicitly_wait(20)
+        # 向下滑动页面,展示出小程序选择面板
+        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(5)
-            cls.get_videoList(log_type, crawler, driver, env)
+        time.sleep(5)
+        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)
+        cls.quit(log_type, crawler, driver)
+        # except Exception as e:
+        #     Common.logger(log_type, crawler).error('start_wechat异常:{}\n', e)
 
     @classmethod
     def quit(cls, log_type, crawler, driver: WebDriver):