yidong(1).py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. from PIL import Image
  7. import time
  8. class yidong:
  9. def __init__(self, drivePath, money, tel, password, options=Options()):
  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 Cancel_order(self):
  39. try:
  40. self.chrome.find_element(By.XPATH, '//*[@id="sure-btn"]').click()
  41. self.chrome.find_element(By.XPATH, '//*[@id="orderList"]/tbody/tr[1]/td[7]/a[2]').click()
  42. jd = self.chrome.find_elements(By.CSS_SELECTOR, 'div.ued-plusdialog')[1]
  43. jd.find_element(By.CSS_SELECTOR, 'div.dialog-footer > input:nth-child(1)').click()
  44. print(">>> 检测到订单!已取消!")
  45. self.chrome.get('https://login.10086.cn/login.html?channelID=12003&backUrl=https://shop.10086.cn/i/?f=rechargecredit')
  46. self.chrome.switch_to.window(self.chrome.window_handles[-1])
  47. except:
  48. return
  49. def invest_page(self):
  50. self.Cancel_order()
  51. self.chrome.find_element(By.XPATH, '//*[@id="stc-money-input"]').send_keys(self.money)
  52. self.chrome.find_element(By.XPATH, '//*[@id="stc-recharge-submit"]').click()
  53. time.sleep(3)
  54. # 将控制权转为最后打开的标签页面
  55. self.chrome.switch_to.window(self.chrome.window_handles[-1])
  56. self.chrome.find_element(By.XPATH, '//*[@id="payment"]/div/ul/li[3]/label/input').click()
  57. self.chrome.find_element(By.XPATH, '//*[@id="payment"]/div/p/input').click()
  58. self.chrome.switch_to.window(self.chrome.window_handles[-1])
  59. time.sleep(2)
  60. self.chrome.find_element(By.XPATH, '//*[@id="J_qrPayArea"]/div[3]/div[1]').screenshot('payImg.png')
  61. img = Image.open('payImg.png')
  62. img.show()
  63. src_url = self.chrome.current_url
  64. while True:
  65. if src_url == self.chrome.current_url:
  66. time.sleep(5)
  67. else:
  68. img.close()
  69. print(f">>> 充值完成 充值金额 {self.money}")
  70. if __name__ == "__main__":
  71. Yidong = yidong(drivePath=r'D:\chrome\chromedriver.exe', money=10, tel='18731276617', password='289311')
  72. Yidong.login_page()
  73. Yidong.invest_page()