Skip to content

12306

Python script that automates searching and booking China 12306 train tickets; repo is archived.

Stars
34k
Forks
9.6k
Licence
MIT
Language
Python
Last update
3.6 years ago
Type
CLI

This repository is archived and no longer maintained.

What it is

This is a Python command-line helper for buying Chinese railway tickets on the 12306 booking site. It logs in, repeatedly checks for seats on chosen trains, and tries to submit orders, including handling captchas and sending email or Server酱 notifications. The repository was last pushed in April 2023 and is marked archived, so it is no longer maintained.

  • Edit TickerConfig.py with travel dates and train preferences, then run the script to watch for available seats
  • Use the test option to check whether email or Server酱 notifications work
  • Run the CDN filter step before starting the booking loop, as the README recommends
  • Study the module layout described in the README (agency, config, verify, init, inter, myException, myUrllib)

Great for

  • Developers who want to study how a Python ticket-booking script is structured
  • People who need to book Chinese train tickets and are comfortable editing a Python config file
  • Users who can run Python 3.6 to 3.7.4 on a home network

Not ideal for

  • Anyone expecting ongoing updates, since the repo is archived and last pushed in 2023
  • People on the 12306 site who need a supported, official booking route, since the README says 12306 is sensitive to server IPs and the tool is for learning and exchange only
  • Users on newer Python versions, since the README lists only 3.6 to 3.7.4 as tested

How to get it

  1. 1

    Clone and build from source

    You'll need: Python 3.6 to 3.7.4 (per README) · pip3 · Docker 18.09+ and docker-compose 1.23.2+ (only for the Docker option)

    Clone the repository

    git clone https://github.com/testerSunshine/12306.git

    Install dependencies (root user)

    pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
  2. 2

    Run it

    • Edit TickerConfig.py, paying attention to spaces and Python syntax
    • Run python3 run.py t to test email and Server酱 notifications
    • Run python3 run.py c to filter CDNs before starting
    • Run python3 run.py r to start the booking program
  3. 3

    Get the most out of it

    • Use python3 run.py -h to see the available operations (r, c, t)
    • Download the captcha model from the link in the README and place it in the project root for local captcha recognition
    • Set up Server酱 notifications following the linked tutorial in the README
    • Use the Docker Compose route in the README if you have a server with Docker installed

Downloads

Strengths

  • Covers login, captcha handling, and waitlist (智能候补) features listed in the README
  • Offers notifications by email and Server酱
  • Has a Docker Compose option described in the README for running it in a container

Trade-offs

  • Archived and last pushed April 2023, so it may not match the current 12306 site
  • README says it is for learning and exchange only and warns against commercial use
  • The README says the captcha model must be downloaded separately and that cloud servers often get blocked

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.