当前位置:   article > 正文

大麦抢票-Appium实现抢票软件-APP自动化_python+appium抢票

python+appium抢票

环境介绍:Python 3.9.1

自行下载appium和相关依赖

本代码是无聊写的,运行也正常,但是就是抢不到,抢票需要天时,地利,人和,不要用UI最好

我链接的是夜神虚拟模拟器

特此说明:所有的UI自动化抢票以个人见解,95%往上抢不到票

  1. import os
  2. from appium import webdriver
  3. import time
  4. from selenium.webdriver.common.by import By
  5. def get_size(driver):
  6. x = driver.get_window_size()['width']
  7. y = driver.get_window_size()['height']
  8. return x, y
  9. def swipe_down(driver, t):
  10. """
  11. 滑动时X轴不变,Y轴由小到大
  12. """
  13. screensize = get_size(driver)
  14. x1 = int(screensize[0] * 0.5) # x坐标
  15. y1 = int(screensize[1] * 0.25) # 起始y坐标
  16. y2 = int(screensize[1] * 0.75) # 终点y坐标
  17. driver.swipe(x1, y1, x1, y2, t)
  18. heard = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"}
  19. desired_caps = {
  20. "platformName": "Android",
  21. "platformVersion": "7.1.3",
  22. "appPackage": "cn.damai",
  23. "appActivity": "cn.damai.search.v2.SearchActivity",
  24. "noReset": True,
  25. "adbExecTimeout": 200000,
  26. "headers": heard
  27. }
  28. # name = "作者"
  29. # concert_name = "【北京】DEADLINE 小鬼-作者2023巡回演唱会-北京站"
  30. # session = '2023-06-03 周六 19:00'
  31. # money = '看台1580元'
  32. name = "作者"
  33. concert_name = "武汉站"
  34. session = '2023-06-25 周日 19:00'
  35. money = '看台855'
  36. try:
  37. driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps) ##启动服务器地址,后面跟的是手机信息
  38. driver.implicitly_wait(8)
  39. print("开始输入……")
  40. driver.find_element(By.ID, "cn.damai:id/header_search_v2_input").send_keys(name)
  41. driver.find_element(By.XPATH, '//android.widget.TextView[@text="{}"]'.format(name)).click()
  42. time.sleep(0.5)
  43. #获取演唱会场次
  44. # try:
  45. # print('点击场次') # 但是时间点长
  46. # driver.find_element(By.XPATH, "//*[@text='{}']".format(concert_name)).click()
  47. # except:
  48. # print('点击场次')#需要手动配置
  49. # driver.tap([(186, 280), (864, 364)], 300)
  50. # driver.tap([(186, 280), (864, 364)], 300)
  51. time.sleep(1)
  52. #获取当前是否能够购买,如果能够购买直接进入
  53. sell_status = driver.find_element(By.ID, "cn.damai:id/tv_left_main_text").text
  54. while True:
  55. print('现在售票状态处于:{}中....'.format(sell_status))
  56. if sell_status.strip() == '立即预定' or sell_status.strip() == '立即购买':
  57. driver.find_element(By.ID, "cn.damai:id/tv_left_main_text").click()
  58. break
  59. else:
  60. # 点击立即购买
  61. swipe_down(driver, 200)
  62. # time.sleep(0.1)
  63. sell_status = driver.find_element(By.ID, "cn.damai:id/tv_left_main_text").text
  64. time.sleep(0.5)
  65. #选择场次
  66. try:
  67. while True:
  68. driver.find_element(By.XPATH, "//android.widget.TextView[@text='{}']".format(session)).click()
  69. time.sleep(0.1)
  70. driver.find_element(By.XPATH, "//android.widget.TextView[@text='{}']".format(money)).click()
  71. #点击立即确定
  72. driver.tap([(354, 1496), (546, 1584)], 300)
  73. time.sleep(0.1)
  74. try:
  75. driver.find_element(By.ID,"cn.damai:id/damai_theme_dialog_confirm_btn")
  76. driver.find_element(By.ID, "cn.damai:id/damai_theme_dialog_confirm_btn").click()
  77. time.sleep(0.5)
  78. except:
  79. break
  80. #处理票价
  81. # num = 1
  82. # while num > 1:
  83. # driver.find_element(By.ID, "cn.damai:id/img_jia").click()
  84. # num -= 1
  85. # driver.tap([(450, 1496), (858, 1584)], 300)
  86. # driver.find_element(By.XPATH, '//android.widget.TextView[@text="马茂财"]').click()
  87. # try:
  88. # driver.find_element(By.XPATH,'//android.widget.TextView[@text="支付宝"]').click()
  89. # except:
  90. # pass
  91. #点击确定
  92. driver.tap([(658, 1500), (858, 1580)], 300)
  93. except:
  94. driver.find_element(By.ID, "cn.damai:id/damai_theme_dialog_cancel_btn']").click()
  95. driver.tap([(354, 1496), (546, 1584)], 300)
  96. time.sleep(0.5)
  97. # try:
  98. # driver.find_element(By.XPATH, '//android.widget.TextView[@text="预留身份证信息"]')
  99. # except:
  100. #处理票价
  101. # num = 1
  102. # while num > 1:
  103. # driver.find_element(By.ID, "cn.damai:id/img_jia").click()
  104. # num -= 1
  105. driver.tap([(450, 1496), (858, 1584)], 300)
  106. # driver.find_element(By.XPATH, '//android.widget.TextView[@text="预留身份证信息"]').click()
  107. # try:
  108. # driver.find_element(By.XPATH,'//android.widget.TextView[@text="支付宝"]').click()
  109. # except:
  110. # pass
  111. #点击确定
  112. driver.tap([(658, 1500), (858, 1580)], 300)
  113. except Exception as e:
  114. raise Exception(e)
  115. finally:
  116. os.system("adb uninstall io.appium.settings")
  117. # os.system("adb uninstall io.appium.unlock")
  118. # driver.quit()

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/472415
推荐阅读
相关标签
  

闽ICP备14008679号