溫習(xí)Python時(shí)晌杰,偶然發(fā)現(xiàn)去年跟朋友用selenium寫的一個(gè)怒刷網(wǎng)頁游戲后臺(tái)道具的代碼筷弦!
selenium以前用了一段時(shí)間,后來工作中不長用就沒怎么看了烂琴。
from selenium import webdriver
import time
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
# 自己可以加個(gè)全局等待時(shí)間
# 東 游戲后臺(tái) 無限刷內(nèi)丹
mhxy = webdriver.Firefox()
def logingWeb(url,user,paw):
mhxy.get(url) # 網(wǎng)頁已不存在!
time.sleep(1)
#點(diǎn)擊警告框
mhxy.switch_to_alert().accept()
#輸入用戶名
time.sleep(1)
mhxy.find_element_by_id("user").send_keys(user)
#輸入密碼
time.sleep(1)
mhxy.find_element_by_id("pass").send_keys(paw)
mhxy.find_element_by_id('user').click()
#點(diǎn)擊登陸
time.sleep(2)
mhxy.find_element_by_xpath\
("/html/body/div/form/div[2]/button")\
.click()
#點(diǎn)擊郵箱系統(tǒng)
time.sleep(1)
mhxy.find_element_by_xpath\
("/html/body/div/button[2]").click()
# 選擇 物品 種類 數(shù)量 發(fā)送 確定
def sendmail():
#下拉框選物品
time.sleep(0.5)
Select(mhxy.find_element_by_id("itemtype")).select_by_value("1")
#下拉框選擇攻擊丹
time.sleep(0.5)
Select(mhxy.find_element_by_id("item")).select_by_value("2006706")
#點(diǎn)擊 物品數(shù)量
time.sleep(0.5)
mhxy.find_element_by_id('num').send_keys(Keys.BACKSPACE)
mhxy.find_element_by_id("num").send_keys("999")
time.sleep(0.5)
#點(diǎn)擊發(fā)送
mhxy.find_element_by_xpath\
("/html/body/div/form[2]/div[2]/fieldset/div[2]/div[1]/button").click()
#點(diǎn)擊警告框
time.sleep(0.5)
mhxy.switch_to_alert().accept()
if __name__ == '__main__':
url = ""
user = "Yorki"
paw = "123123"
logingWeb(url,user,paw)
for j in range(1,3): #循環(huán)3次
for i in range(1,100): #循環(huán)100次
sendmail()
print("休息30秒",j)
time.sleep(3)