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