12306 Ticket-grabbing artifact to help you who want to go home far away

Modify the configuration file: TickerConfig

  • Automatic coding, set to 2
AUTO_CODE_TYPE = 2 # 听他的吧,否则就是执行不下去了,即使是2也不影响;
  • No need to send email, set False
EMAIL_CONF = {
    "IS_MAIL": False,
    "email": "",
    "notice_email_list": "",
    "username": "",
    "password": "",
    "host": "smtp.qq.com",
}
  • Do not configure the selenium environment, set COOKIE_TYPE=3
# 如果COOKIE_TYPE=3, 则需配置RAIL_EXPIRATION、RAIL_DEVICEID的值
RAIL_EXPIRATION = ""
RAIL_DEVICEID = ""

  • Pay attention to WeChat reminder: SERVER_CHAN_CONF, optional
# 前往 http://sc.ftqq.com/3.version 扫码绑定获取 SECRET
SERVER_CHAN_CONF = {
    "is_server_chan": True,
    "secret": "SCT76378TuaIlPCkz8OkWcUJwvlJoAe7Q"
}

  • Other configuration items are kept as default, and only the ride date, pre-sale time, rider, and shift information can be replaced.

Start running: python run.py r

If the proxy is enabled, first add ip to proxy_list and execute: python run.py c

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

  • Then you can only find the source code for debugging: inter/SubmitOrderRequest file.submitOrderRequest class.sendSubmitOrderRequest method
def sendSubmitOrderRequest(self):
    """
    提交车次
    预定的请求参数,注意参数顺序
    注意这里为了防止secretStr被urllib.parse过度编码,在这里进行一次解码
    否则调用HttpTester类的post方法将会将secretStr编码成为无效码,造成提交预定请求失败
    :param secretStr: 提交车次加密
    :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'出票失败')
    elif 'messages' in submitResult and submitResult['messages']:
        raise ticketIsExitsException(submitResult['messages'][0])

Analyze source code

When submitting an order request, I skip directly in the second if condition, and when I go to the else, it is over, and I don't check the order at all, so the author prints (submitResult) in the outer layer to see what the data of this result is?

  • ?excuse me, turned out to be "0", not "N"
{'validateMessagesShowId': '_validatorMessage', 'status': True, 'httpstatus': 200, 'data': '0', 'messages': [], 'validateMessages': {}}
  • Doubt: The account must be able to query the remaining tickets normally and place the order successfully. There is no possibility that the purchase cannot be made, so the guess is that the return parameter of 12306 has changed, so that the script does not follow the booking logic (after all, it is the code from two years ago), so change the source code , let the second if equal to "0", remember it is a string.
if submitResult['data'] == "0": # 原来的右边条件是:"N"
  • Execute again, the result is as follows, the booking is successful!

  • So I hurried to 12306's app to check, and sure enough, there were unpaid orders, which is really amazing.

The debugging of the local running code is successful, just wait for the results tomorrow to see if the booking will be successful, otherwise, you will still be unable to get rid of the fate of looking for scalpers!!!

Today's content is shared here, and the editor finally prepared a python spree for everyone [Jiajun Yang: 419693945] to help you learn programming better!

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324342145&siteId=291194637