DracoYan-111 / damai_grab_votes

大麦抢票网页端 安卓端
244 stars 36 forks source link

(忙碌中...,随缘更新)大麦抢票脚本 V1.0

!!!已经有大佬成功的跑起来了,代码能运行,就是可能会被锁ip,这个很难处理,斟酌后再使用哈

特征

该项目的魔改版本,老哥牛逼 @WECENG https://github.com/WECENG/ticket-purchase

(以下文档有空再更新,具体看代码注释,代码能跑就行😂)

功能介绍

通过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 文件内容说明

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_commit_order": true
}

3.运行程序

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

cd damai
python3 damai.py

大麦app抢票

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

appium server

下载

​ 可能会遇到如下错误:

➜  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

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

[Appium] Welcome to Appium v2.5.1
[Appium] The autodetected Appium home path: xxxxxx
[Appium] Attempting to load driver uiautomator2...
[Appium] Requiring driver at xxxxxx/index.js
[Appium] AndroidUiautomator2Driver has been successfully loaded in 0.459s
[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.24.31.70:4723/
[Appium]        http://198.18.0.1:4723/
[Appium] Available drivers:
[Appium]   - uiautomator2@3.0.2 (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