background

Every festival times miss relatives, close to the year, homesick mood is not increasingly strong, they are not ready to start grabbing tickets, or looking for scalpers? However, this year in consideration of whether to grab tickets, but also need to consider whether to go back, yes, because of the epidemic, the need for the national people to work together to fight against the epidemic, WE can not give the motherland mother trouble, just hope that everyone is happy!

scalpers

How does it get to be good enough to get tickets out of the mud, when it’s a 12306 insider? A relative of his? But also so bovine force coax coaxed asking price, The Spring Festival to increase the price of 100 yuan/ticket, so that the original 200 yuan ticket increased 70%, is there any way to solve this phenomenon? Some of them are also through the VIP function of buying someone else’s tools (it is said that the annual renewal is relatively cost-effective), as well as the VIP price increase function of other transportation apps, well, the author is not successful! Also almost a price with the scalper, it is better to the scalper worry.

Automatic ticket grab script

As an author who is half a programmer, I am not comfortable with the new environment. I also tried to write my own script to solve the problem, but one year I was defeated by the image verification code, and nothing came to an end. Not long ago, I saw the script of stealing tickets highly respected by others and opened it on Github. Star is so high that it is not an order of magnitude stronger than the author’s 35 stars. Finally, the author couldn’t resist the curiosity to try the depth.

Clone the code locally

Git clone github.com/testerSunsh…

Read readme. md to configure the Python runtime environment. Do not cut corners on the required features.

Modify the TickerConfig configuration file

  • Automatic coding, set to 2
AUTO_CODE_TYPE = 2 # listen to him, otherwise it will not work, even if it is 2;Copy the code
  • No need to send email, set False
EMAIL_CONF = {
    "IS_MAIL": False,
    "email": "",
    "notice_email_list": "",
    "username": "",
    "password": "",
    "host": "smtp.qq.com",
}
Copy the code
  • Leave the Selenium environment unconfigured and set COOKIE_TYPE=3
If COOKIE_TYPE=3, configure RAIL_EXPIRATION = "" RAIL_EXPIRATION = "" RAIL_DEVICEID = ""Copy the code
    • Where to find the value? Browser :www.12306.cn; Open F12– Cookies and you can find yourself on the right side

  • SERVER_CHAN_CONF, optional
# http://sc.ftqq.com/3.version for scan code binding for SECRET SERVER_CHAN_CONF = {" is_server_chan ": True," SECRET ": "SCT76378TuaIlPCkz8OkWcUJwvlJoAe7Q" }Copy the code

  • For other configuration items, keep the default, only replace the date of ride, booking time, passenger and flight information.

Start: Python run.py r

To enable proxies, add IP to proxy_list and run python run.py c

  • Oh oh, the execution result failed to issue the ticket, this is impossible, the account local test can log in to submit the order, there should not be failure;

  • So only find the source code debugging: Inter /SubmitOrderRequest file, SubmitOrderRequest class, sendSubmitOrderRequest method
def sendSubmitOrderRequest(self) :
    To prevent secretStr from being over-encoded by urllib.parse, Otherwise calling the POST method of the HttpTester class will encode secretStr as an invalid code, resulting in a failure to submit the scheduled request :param secretStr: Submit the number of times encrypted :return: """
    submit_station_url = self.session.urls["submit_station_url"]
    submitResult = self.session.httpClint.send(submit_station_url, self.data_apr())
    Print (submitResult
    if 'data' in submitResult and submitResult['data'] :if submitResult['data'] = ="N":
            coi = checkOrderInfo(self.session, self.train_no, self.set_type, self.passengerTicketStrList,
                                 self.oldPassengerStr,
                                 self.train_date, self.ticke_peoples)
            coi.sendCheckOrderInfo()
        else:
            print (U 'failed to issue ticket')
    elif 'messages' in submitResult and submitResult['messages'] :raise ticketIsExitsException(submitResult['messages'] [0])
Copy the code

Analysis of the source code

Print (submitResult) print(submitResult) print(submitResult) print(submitResult)

  • ? Excuse me, “0”, not “N”
{'validateMessagesShowId': '_validatorMessage', 'status': True, 'httpstatus': 200, 'data': '0', 'messages': [], 'validateMessages': {}}
Copy the code
  • 12306 return parameter changed, let the script did not go booking logic (after all is two years ago the code), so change the source code, let the second if equal to “0”, remember is a string oh.
if submitResult['data'] = ="0": # N = "N"
Copy the code
  • Execute again, result is as follows, booking successful!

  • So quickly ran to 12306 app check, as expected there were unpaid orders, is really too powerful.

Wait and see

The local running code debugging is successful, only wait for tomorrow to check the results, whether the ticket will be successful, or can not get rid of the fate of scalpers!!

I just hope the epidemic can be controlled, otherwise even if there are tickets, depending on the severity of the situation, the line may be shut down.