python 躺着刷视频(自动刷视频)
生活随笔
收集整理的這篇文章主要介紹了
python 躺着刷视频(自动刷视频)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
代碼實現
from appium import webdriver from selenium.webdriver.common.by import By import time import subprocess import randomdef kuaishou(adb_name):adb_path = r"D:\adb\adb.exe"# Appium Server連接的參數desired_caps = {'platformName': 'Android', # 被測手機是安卓'platformVersion': '7', # 手機安卓版本'deviceName': 'xxx', # 設備名,安卓手機可以隨意填寫'appPackage': 'com.kuaishou.nebula', # 啟動APP Package名稱'appActivity': 'com.yxcorp.gifshow.HomeActivity', # 啟動Activity名稱'unicodeKeyboard': True, # 使用自帶輸入法,輸入中文時填True'resetKeyboard': True, # 執行完程序恢復原來輸入法'noReset': True, # 不要重置App'newCommandTimeout': 6000,'automationName' : 'UiAutomator2'}# 連接Appium Server,初始化自動化環境driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)num = 0elapsed = 0judge = 0box = 1while True:try:# 設置等待時間等待driver.implicitly_wait(40)# 是否出現評論圖標Comment_icon = driver.find_elements(By.ID, "com.kuaishou.nebula:id/comment_icon")print(bool(Comment_icon),'出現評論圖標')# 如果頁面沒有出現評論圖標就進行等待if bool(Comment_icon) == False:# 鍵盤返回一下subprocess.getoutput(f"{adb_path} -s {adb_name} shell input keyevent 4")continue# 刷視頻start = time.time()subprocess.getoutput(f"{adb_path} -s {adb_name} shell input swipe 360 1000 360 120")sleep_time = random.randint(7, 12)time.sleep(sleep_time)num += 1print('觀看第{}個視頻,觀看{}秒'.format(num, sleep_time))end = time.time()elapsed += int(end - start)# 如果刷到的下一個視頻是直播或者看圖片的就過濾掉Comment_icon = driver.find_elements(By.ID, "com.kuaishou.nebula:id/comment_icon")if bool(Comment_icon) == False:print(bool(Comment_icon), '是直播,圖片或其他異常,過濾掉')continueif judge <= elapsed:print('寶箱的時間到了')if Comment_icon:# 點擊紅包,進入任務主頁subprocess.getoutput(f"{adb_path} -s {adb_name} shell input tap 68 750")# 定位任務頁面 xpath定位的是 我的抵用金tasks = driver.find_elements(By.XPATH,"/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.widget.ListView/android.view.View[2]/android.view.View[1]/android.widget.TextView")# 判斷是否進入任務頁面if tasks:print('進入任務頁面')time.sleep(2)# 點擊寶箱subprocess.getoutput(f"{adb_path} -s {adb_name} shell input tap 604 1155")time.sleep(2)# 返回subprocess.getoutput(f"{adb_path} -s {adb_name} shell input keyevent 4")print(f'寶箱已領{box}個')judge += 1200box += 1# 如果沒有定位到 “進入任務主頁” 和 “我的抵用金” 就返回if (bool(Comment_icon) == False) and (bool(tasks) == False):subprocess.getoutput(f"{adb_path} -s {adb_name} shell input keyevent 4")except:print('出錯了,重啟')subprocess.getoutput(f"{adb_path} -s {adb_name} shell am force-stop com.kuaishou.nebula")kuaishou(adb_name)def RW(adb_name, num=1):adb_path = r"D:\adb\adb.exe"# Appium Server連接的參數desired_caps = {'platformName': 'Android', # 被測手機是安卓'platformVersion': '7', # 手機安卓版本'deviceName': 'xxx', # 設備名,安卓手機可以隨意填寫'appPackage': 'com.kuaishou.nebula', # 啟動APP Package名稱'appActivity': 'com.yxcorp.gifshow.HomeActivity', # 啟動Activity名稱'unicodeKeyboard': True, # 使用自帶輸入法,輸入中文時填True'resetKeyboard': True, # 執行完程序恢復原來輸入法'noReset': True, # 不要重置App'newCommandTimeout': 6000,'automationName' : 'UiAutomator2'}# 連接Appium Server,初始化自動化環境driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)while True:try:# 設置等待時間等待driver.implicitly_wait(40)# 是否出現評論圖標Comment_icon = driver.find_elements(By.ID, "com.kuaishou.nebula:id/comment_icon")print(bool(Comment_icon),'出現評論圖標')# 如果頁面沒有出現評論圖標就進行等待if bool(Comment_icon) == False:# 鍵盤返回一下subprocess.getoutput(f"{adb_path} -s {adb_name} shell input keyevent 4")continue# 點擊紅包進入任務頁面subprocess.getoutput(f"{adb_path} -s {adb_name} shell input tap 68 750")# 定位任務頁面 xpath定位的是 我的抵用金tasks = driver.find_elements(By.XPATH,"/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.widget.ListView/android.view.View[2]/android.view.View[1]/android.widget.TextView")# 判斷是否進入任務頁面if tasks:time.sleep(3)for i in range(10):# 滑動任務頁面subprocess.getoutput(f"{adb_path} -s {adb_name} shell input swipe 352 1077 352 777")# 定位看廣告的任務welfare = driver.find_elements(By.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View[4]/android.view.View[1]")if welfare:breakelse:continuefor i in range(12-num):# 定位看廣告的任務welfare = driver.find_elements(By.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View[4]/android.view.View[1]")# 判斷是否有看廣告的任務if welfare:print('定位到看廣告的任務')# 有看廣告的任務,則點擊welfare[0].click()# 等看完廣告了就退出time.sleep(45)subprocess.getoutput(f"{adb_path} -s {adb_name} shell input tap 489 46")print('已完成{}次觀看廣告任務'.format(num))num += 1time.sleep(1)# 判斷是否完成了10次觀看,如果完成就結束if num == 10:returnexcept:print('出錯了,重新開始')# 判斷是否完成了10次觀看,如果完成就結束if num == 10:returnRW(adb_name, num)adb_name = input('請輸入模擬器的編號:') # 例如:emulator-5558 RW(adb_name) kuaishou(adb_name)如果不知道自己的模擬器編號的話,可以按照下面的步驟獲取:
- 先打開模擬器
- 再打開win+r 輸入命令 adb devices
emulator-5558這個就是你虛擬機的編號名稱
使用步驟
為了方便大家,我已經把這些安裝包全部放在百度網盤了,大家自行下載吧
鏈接:https://pan.baidu.com/s/14_D_tLNjcWu3MGI3NyfXbA
提取碼:glym
第一個:
安裝雷電模擬器,這種的就是傻瓜式安裝就好了
第二個:
安裝appium,這種的也是傻瓜式安裝就好了,然后設置模擬器:
然后在設置里面進入開發者選項
第三個:
把androidsdk這個文件夾放在合適的盤下,再添加到環境變量里面就好了
第四個:
安裝jdk環境,然后添加到環境變量里面就好了
第五個:
python安裝的第三方庫:
pip install appium-python-client
pip install selenium
第六個
先運行appium
再運行雷電模擬器
最后就可以運行python腳本了
感謝你的閱讀,你的三連是我分享的動力!
總結
以上是生活随笔為你收集整理的python 躺着刷视频(自动刷视频)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 深圳高层次人才认定,你了解吗?
- 下一篇: 软件工程毕业设计课题(25)基于JAVA