Giter Club home page Giter Club logo

ticket-purchase's Introduction

大麦抢票脚本 V1.0

特征

  • 自动无延时抢票
  • 支持人员、城市、日期场次、价格选择

功能介绍

通过selenium打开页面进行登录,模拟用户购票流程自动购票

其流程图如下:

准备工作

1. 配置环境

1.1安装python3环境

Windows

  1. 访问Python官方网站:https://www.python.org/downloads/windows/
  2. 下载最新的Python 3.9+版本的安装程序。
  3. 运行安装程序。
  4. 在安装程序中,确保勾选 "Add Python X.X to PATH" 选项,这将自动将Python添加到系统环境变量中,方便在命令行中使用Python。
  5. 完成安装后,你可以在命令提示符或PowerShell中输入 python3 来启动Python解释器。

macOS

  1. 你可以使用Homebrew来安装Python 3。

    • 安装Homebrew(如果未安装):打开终端并运行以下命令:

      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    • 安装Python 3:运行以下命令来安装Python 3:

      brew install python@3

1.2 安装所需要的环境

在命令窗口输入如下指令

pip3 install selenium

1.3 下载google chrome浏览器

下载地址: https://www.google.cn/intl/zh-CN/chrome/?brand=YTUH&gclid=Cj0KCQjwj5mpBhDJARIsAOVjBdoV_1sBwdqKGHV3rUU1vJmNKZdy5QNzbRT8F5O0-_jq1WHXurE8a7MaAkWrEALw_wcB&gclsrc=aw.ds

2. 修改配置文件

在运行程序之前,需要先修改config.json文件。该文件用于指定用户需要抢票的相关信息,包括演唱会的场次、观演的人员、城市、日期、价格等。文件结果如下图所示:

2.1 文件内容说明

  • index_url为大麦网的地址,无需修改
  • login_url为大麦网的登录地址,无需修改
  • target_url为用户需要抢的演唱会票的目标地址,待修改
  • users为观演人的姓名,观演人需要用户在手机大麦APP中先填写好,然后再填入该配置文件中待修改
  • city为城市,如果用户需要抢的演唱会票需要选择城市,请把城市填入此处。如无需选择,则不填
  • date为场次日期,待修改,可多选
  • price为票档的价格,待修改,可多选
  • if_commit_order为是否要自动提交订单,改成 true
  • if_listen为是否回流监听,改成true

2.2 示例说明

进入大麦网https://www.damai.cn/,选择你需要抢票的演唱会。假设如下图所示:

接下来按照下图的标注对配置文件进行修改:

最终config.json的文件内容如下:

{
  "index_url": "https://www.damai.cn/",
  "login_url": "https://passport.damai.cn/login?ru=https%3A%2F%2Fwww.damai.cn%2F",
  "target_url": "https://detail.damai.cn/item.htm?spm=a2oeg.home.card_0.ditem_1.591b23e1JQGWHg&id=740680932762",
  "users": [
    "名字1",
    "名字2"
  ],
  "city": "广州",
  "date": "2023-10-28",
  "price": "1039",
  "if_listen":true,
  "if_commit_order": true
}

3.运行程序

运行程序开始抢票,进入命令窗口,执行如下命令:

cd damai
python3 damai.py

大麦app抢票

大麦app抢票脚本需要依赖appium,因此需要现在安装appium server&client环境,步骤如下:

appium server

下载

  • 先安装好node环境(具备npm)node版本号18.0.0

  • 先下载并安装好android sdk,并配置环境变量(appium server运行需依赖android sdk)

  • 下载appium

    npm install -g appium
  • 查看appium是否安装成功

    appium -v
  • 下载UiAutomator2驱动

    npm install appium-uiautomator2-driver

​ 可能会遇到如下错误:

➜  xcode git:(master) ✗ npm install appium-uiautomator2-driver

npm ERR! code 1
npm ERR! path /Users/chenweicheng/Documents/xcode/node_modules/appium-uiautomator2-driver/node_modules/appium-chromedriver
npm ERR! command failed
npm ERR! command sh -c node install-npm.js
npm ERR! [11:57:54] Error installing Chromedriver: Request failed with status code 404
npm ERR! [11:57:54] AxiosError: Request failed with status code 404
npm ERR!     at settle (/Users/chenweicheng/Documents/xcode/node_modules/appium-uiautomator2-driver/node_modules/axios/lib/core/settle.js:19:12)
npm ERR!     at IncomingMessage.handleStreamEnd (/Users/chenweicheng/Documents/xcode/node_modules/appium-uiautomator2-driver/node_modules/axios/lib/adapters/http.js:572:11)
npm ERR!     at IncomingMessage.emit (node:events:539:35)
npm ERR!     at endReadableNT (node:internal/streams/readable:1344:12)
npm ERR!     at processTicksAndRejections (node:internal/process/task_queues:82:21)
npm ERR! [11:57:54] Downloading Chromedriver can be skipped by setting the'APPIUM_SKIP_CHROMEDRIVER_INSTALL' environment variable.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/chenweicheng/.npm/_logs/2023-10-26T03_57_35_950Z-debug-0.log

​ 解决办法(添加环境变量,错误原因是没有找到chrome浏览器驱动,忽略即可)

export APPIUM_SKIP_CHROMEDRIVER_INSTALL=true

启动

启动appium server并使用uiautomator2驱动

appium --use-plugins uiautomator2

启动成功将出现如下信息:

[Appium] Welcome to Appium v2.2.1 (REV 2176894a5be5da17a362bf3f20678641a78f4b69)
[Appium] Non-default server args:
[Appium] {
[Appium]   usePlugins: [
[Appium]     'uiautomator2'
[Appium]   ]
[Appium] }
[Appium] Attempting to load driver uiautomator2...
[Appium] Requiring driver at /Users/chenweicheng/Documents/xcode/node_modules/appium-uiautomator2-driver
[Appium] Appium REST http interface listener started on http://0.0.0.0:4723
[Appium] You can provide the following URLs in your client code to connect to this server:
[Appium] 	http://127.0.0.1:4723/ (only accessible from the same host)
[Appium] 	http://172.31.102.45:4723/
[Appium] 	http://198.18.0.1:4723/
[Appium] Available drivers:
[Appium]   - [email protected] (automationName 'UiAutomator2')
[Appium] No plugins have been installed. Use the "appium plugin" command to install the one(s) you want to use.

其中[Appium] http://127.0.0.1:4723/ (only accessible from the same host) [Appium] http://172.31.102.45:4723/ [Appium] http://198.18.0.1:4723/为appium server连接地址

appium client

  • 先下载并安装好python3和pip3

  • 安装

    pip3 install appium-python-client
  • 在代码中引入并使用appium

    from appium import webdriver
    from appium.options.common.base import AppiumOptions
    
    device_app_info = AppiumOptions()
    device_app_info.set_capability('platformName', 'Android')
    device_app_info.set_capability('platformVersion', '10')
    device_app_info.set_capability('deviceName', 'YourDeviceName')
    device_app_info.set_capability('appPackage', 'cn.damai')
    device_app_info.set_capability('appActivity', '.launcher.splash.SplashMainActivity')
    device_app_info.set_capability('unicodeKeyboard', True)
    device_app_info.set_capability('resetKeyboard', True)
    device_app_info.set_capability('noReset', True)
    device_app_info.set_capability('newCommandTimeout', 6000)
    device_app_info.set_capability('automationName', 'UiAutomator2')
    
    # 连接appium server,server地址查看appium启动信息
    driver = webdriver.Remote('http://127.0.0.1:4723', options=device_app_info)
  • 启动脚本程序

    cd damai_appium
    python3 damai_appium.py

ticket-purchase's People

Contributors

thomas-art avatar weceng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ticket-purchase's Issues

appium的信息

启动服务器后,还有一条这个:[Appium] No drivers have been installed in C:\Users\ACIP.appium. Use the "appium driver" command to install the one(s) you want to use.

运行没有响应

我配置好了环境,启动了appium server并使用uiautomator2驱动
image
然后我新开窗口运行了python3 damai_appium.py,没有弹出窗口
image

中间是不是我哪步漏掉了,对安卓调试这块不是很熟悉,作者能不能讲解一下教程,【在代码中引入并使用appium】这块内容要在哪里配置,还有我这个流程对不对,是直接连上手机 运行py吗

网页版bug

网页版的,在选择人员和座位那里遇到问题,它网页中没有相关的表单信息弹出,所以不能继续进行,还望作者可以支持!感谢!

启动失败

image
我已经pip3中安装了appium-python-client
运行后还是报错找不到appium,这是什么原因大佬
image

版本太新了吗

Traceback (most recent call last):
File "/Users/user/WorkSpace/ticket-purchase/damai_appium/damai_app.py", line 53, in
driver.find_element(by=By.ID, value='homepage_header_search_btn').click()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/appium/webdriver/webdriver.py", line 381, in find_element
return self.execute(RemoteCommand.FIND_ELEMENT, {'using': by, 'value': value})['value']
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 347, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.11/site-packages/appium/webdriver/errorhandler.py", line 125, in check_response
raise exception_class(msg=message, stacktrace=format_stacktrace(stacktrace))
selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception

是版本太新了吗

有偿代抢热门演唱会票

有偿代抢热门演唱会票,服务费票价5%~10%,具体看心情,成功率8成,不包一定抢到,抢到付款无风险,抢票需服从调剂,即任何场次任何座位想看就别挑!

报错

io.appium.uiautomator2.common.exceptions.StaleElementReferenceException: Cached elements 'By.id: tv_tour_city' do not exist in DOM anymore 请问下这个是怎么回事啊?

image

选定城市

想问一下,没有选定城市,config填了空 但是一直卡在选定城市这里 怎么办
image

关于错误的友好提问

票虽然还没开卖,但是出现下面错误:
[26120:21204:0202/023133.666:ERROR:device_event_log_impl.cc(192)] [02:31:33.666] USB: usb_service_win.cc:105 SetupDiGetDeviceProperty({{A45C254E-DF1C-4EFD-8020-67D146A850E0}, 6}) failed: 找不到元素。 (0x490)
error

pyhon版本:3.11.5

抢到票啦

好消息,抢到票啦
IMG_5525

坏消息,手动抢的;😈

关于app使用的几个问题

如果需要使用app,是否还需要安装模拟器呢?

device_app_info = AppiumOptions()
# 操作系统
device_app_info.set_capability('platformName', 'Android')
# 操作系统版本
device_app_info.set_capability('platformVersion', '10')
# 设备名称
device_app_info.set_capability('deviceName', 'YourDeviceName')
# app package
device_app_info.set_capability('appPackage', 'cn.damai')
# app activity name
device_app_info.set_capability('appActivity', '.launcher.splash.SplashMainActivity')
# 使用unicode输入
device_app_info.set_capability('unicodeKeyboard', True)
# 隐藏键盘
device_app_info.set_capability('resetKeyboard', True)
# 不重置app
device_app_info.set_capability('noReset', True)
# 超时时间
device_app_info.set_capability('newCommandTimeout', 6000)
# 使用uiautomator2驱动
device_app_info.set_capability('automationName', 'UiAutomator2')

# 连接appium server,server地址查看appium启动信息
driver = webdriver.Remote(config.server_url, options=device_app_info)

YourDeviceName是指adb devices列出的启动名称嘛?

zsh: command not found: appium

请问下,我npm install -g appium之后查看是否安装成功(appium -v)显示zsh: command not found: appium如何解决呢?
环境:Pycharm,AndroidStudio(SDK,NDK,ADB),Mac,node 18.0.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.