1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- from selenium import webdriver
- from selenium.webdriver.chrome.options import Options
- from selenium.webdriver.chrome.service import Service as EdgeService
- from selenium.webdriver.common.action_chains import ActionChains
- from selenium.webdriver.common.by import By
- import pyautogui
- import time
- class yidong:
- def __init__(self, drivePath, money, tel, password):
-
- self.chrome_options = Options()
- self.chrome_options.add_experimental_option("excludeSwitches",['enable-automation','enable-logging'])
- self.chrome_options.add_argument("--disable-blink-features")
- self.chrome_options.add_argument("--disable-blink-features=AutomationControlled")
- self.chrome_options.add_experimental_option('useAutomationExtension', False)
- # self.chrome_options.add_argument('--headless')
- self.service = EdgeService(executable_path=drivePath)
- self.chrome = webdriver.Edge(service=self.service, options=self.chrome_options)
- self.chrome.implicitly_wait(10)
- self.AC = ActionChains(self.chrome)
- if money % 10 == 0:
- self.money = money
- else:
- print(">>> 金额格式不正确!")
- exit()
- self.tel = tel
- self.password = password
- def login_page(self):
- self.chrome.get('https://login.10086.cn/login.html?channelID=12003&backUrl=https://shop.10086.cn/i/?f=rechargecredit')
- self.AC.move_to_element(self.chrome.find_element(By.XPATH, '//*[@id="J_pc"]'))
- self.AC.click()
- self.AC.perform()
- self.chrome.find_element(By.XPATH, '//*[@id="sms_name"]').send_keys(self.tel)
- self.chrome.find_element(By.XPATH, '//*[@id="getSMSPwd1"]').click()
- code = input(">>> [验证码已发送|等待输入]:")
- self.chrome.find_element(By.XPATH, '//*[@id="sms_pwd_l"]').send_keys(code)
- self.chrome.find_element(By.XPATH, '//*[@id="submit_bt"]').click()
-
- time.sleep(3)
- def invest_page(self):
- self.chrome.find_element(By.XPATH, '//*[@id="stc-money-input"]').send_keys(self.money)
- self.chrome.find_element(By.XPATH, '//*[@id="stc-recharge-submit"]').click()
- time.sleep(3)
- # 将控制权转为最后打开的标签页面
- self.chrome.switch_to.window(self.chrome.window_handles[-1])
- self.chrome.find_element(By.XPATH, '//*[@id="payment"]/div/ul/li[1]/label/input').click()
- self.chrome.find_element(By.XPATH, '//*[@id="payment"]/div/p/input').click()
- self.chrome.switch_to.window(self.chrome.window_handles[-1])
- self.chrome.find_element(By.XPATH, '//*[@id="mblNo"]').send_keys(self.tel)
- self.chrome.find_element(By.XPATH, '//*[@id="paypwdssc"]').clear()
- # self.chrome.find_element(By.XPATH, '//*[@id="paypwdssc"]').send_keys(self.password)
- # self.chrome.execute_script(f'document.getElementById("paypwdssc")[0].value="{self.password}"')
- self.chrome.find_element(By.XPATH, '//*[@id="paypwdssc"]').click()
- for i in self.password:
- pyautogui.press(i)
- self.chrome.find_element(By.XPATH, '//*[@id="loginBtn"]').click()
- self.chrome.find_element(By.XPATH, '//*[@id="sendMSCD"]/span[2]').click()
- code = input(">>> [验证码已发送|等待输入]:")
- self.chrome.find_element(By.XPATH, '//*[@id="VER_CD"]').send_keys(code)
- self.chrome.find_element(By.XPATH, '//*[@id="dealOrder"]').click()
- print(f">>> 充值完成 充值金额 {self.money}")
- if __name__ == "__main__":
- Yidong = yidong(drivePath=r'D:\chrome\chromedriver.exe', money=10, tel='18731276617', password='289311')
- Yidong.login_page()
- Yidong.invest_page()
|