소스 검색

小年糕+ 日志分析,提交了 action 代码,修改滑动的动作

罗俊辉 1 년 전
부모
커밋
de98f9e2c0
1개의 변경된 파일14개의 추가작업 그리고 7개의 파일을 삭제
  1. 14 7
      spider/crawler_offline/xiaoniangao_plus.py

+ 14 - 7
spider/crawler_offline/xiaoniangao_plus.py

@@ -11,6 +11,7 @@ from hashlib import md5
 
 from appium import webdriver
 from appium.webdriver.extensions.android.nativekey import AndroidKey
+from appium.webdriver.common.touch_action import TouchAction
 from bs4 import BeautifulSoup
 from selenium.common.exceptions import NoSuchElementException
 from selenium.webdriver.common.by import By
@@ -139,13 +140,19 @@ class XiaoNianGaoPlusRecommend(object):
     def swipe_up(self):
         self.search_elements('//*[@class="list-list--list"]')
         size = self.driver.get_window_size()
-        self.driver.swipe(
-            int(size["width"] * 0.5),
-            int(size["height"] * 0.8),
-            int(size["width"] * 0.5),
-            int(size["height"] * 0.442),
-            200,
-        )
+        # self.driver.swipe(
+        #     int(size["width"] * 0.5),
+        #     int(size["height"] * 0.8),
+        #     int(size["width"] * 0.5),
+        #     int(size["height"] * 0.442),
+        #     200,
+        # )
+        action = TouchAction(self.driver)
+        action.press(x=int(size["width"] * 0.5), y=int(size["height"] * 0.8))
+        action.wait(ms=200)  # 可以调整等待时间
+        action.move_to(x=int(size["width"] * 0.5), y=int(size["height"] * 0.442))
+        action.release()
+        action.perform()
         self.swipe_count += 1
 
     def get_video_url(self, video_title_element):