yidong.py 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. from selenium import webdriver
  2. from selenium.webdriver.chrome.options import Options
  3. from selenium.webdriver.chrome.service import Service as EdgeService
  4. from selenium.webdriver.common.action_chains import ActionChains
  5. from selenium.webdriver.common.by import By
  6. import pyautogui
  7. import time
  8. class yidong:
  9. def __init__(self, drivePath, money, tel, password):
  10. self.chrome_options = Options()
  11. self.chrome_options.add_experimental_option("excludeSwitches",['enable-automation','enable-logging'])
  12. self.chrome_options.add_argument("--disable-blink-features")
  13. self.chrome_options.add_argument("--disable-blink-features=AutomationControlled")
  14. self.chrome_options.add_experimental_option('useAutomationExtension', False)
  15. # self.chrome_options.add_argument('--headless')
  16. self.service = EdgeService(executable_path=drivePath)
  17. self.chrome = webdriver.Edge(service=self.service, options=self.chrome_options)
  18. self.chrome.implicitly_wait(10)
  19. self.AC = ActionChains(self.chrome)
  20. if money % 10 == 0:
  21. self.money = money
  22. else:
  23. print(">>> 金额格式不正确!")
  24. exit()
  25. self.tel = tel
  26. self.password = password
  27. def login_page(self):
  28. self.chrome.get('https://login.10086.cn/login.html?channelID=12003&backUrl=https://shop.10086.cn/i/?f=rechargecredit')
  29. self.AC.move_to_element(self.chrome.find_element(By.XPATH, '//*[@id="J_pc"]'))
  30. self.AC.click()
  31. self.AC.perform()
  32. self.chrome.find_element(By.XPATH, '//*[@id="sms_name"]').send_keys(self.tel)
  33. self.chrome.find_element(By.XPATH, '//*[@id="getSMSPwd1"]').click()
  34. code = input(">>> [验证码已发送|等待输入]:")
  35. self.chrome.find_element(By.XPATH, '//*[@id="sms_pwd_l"]').send_keys(code)
  36. self.chrome.find_element(By.XPATH, '//*[@id="submit_bt"]').click()
  37. time.sleep(3)
  38. def invest_page(self):
  39. self.chrome.find_element(By.XPATH, '//*[@id="stc-money-input"]').send_keys(self.money)
  40. self.chrome.find_element(By.XPATH, '//*[@id="stc-recharge-submit"]').click()
  41. time.sleep(3)
  42. # 将控制权转为最后打开的标签页面
  43. self.chrome.switch_to.window(self.chrome.window_handles[-1])
  44. self.chrome.find_element(By.XPATH, '//*[@id="payment"]/div/ul/li[1]/label/input').click()
  45. self.chrome.find_element(By.XPATH, '//*[@id="payment"]/div/p/input').click()
  46. self.chrome.switch_to.window(self.chrome.window_handles[-1])
  47. self.chrome.find_element(By.XPATH, '//*[@id="mblNo"]').send_keys(self.tel)
  48. self.chrome.find_element(By.XPATH, '//*[@id="paypwdssc"]').clear()
  49. # self.chrome.find_element(By.XPATH, '//*[@id="paypwdssc"]').send_keys(self.password)
  50. # self.chrome.execute_script(f'document.getElementById("paypwdssc")[0].value="{self.password}"')
  51. self.chrome.find_element(By.XPATH, '//*[@id="paypwdssc"]').click()
  52. for i in self.password:
  53. pyautogui.press(i)
  54. self.chrome.find_element(By.XPATH, '//*[@id="loginBtn"]').click()
  55. self.chrome.find_element(By.XPATH, '//*[@id="sendMSCD"]/span[2]').click()
  56. code = input(">>> [验证码已发送|等待输入]:")
  57. self.chrome.find_element(By.XPATH, '//*[@id="VER_CD"]').send_keys(code)
  58. self.chrome.find_element(By.XPATH, '//*[@id="dealOrder"]').click()
  59. print(f">>> 充值完成 充值金额 {self.money}")
  60. if __name__ == "__main__":
  61. Yidong = yidong(drivePath=r'D:\chrome\chromedriver.exe', money=10, tel='18731276617', password='289311')
  62. Yidong.login_page()
  63. Yidong.invest_page()