The python code for ticket snatching publicly discloses secrets !, Python secrets

Source: Internet
Author: User

The python code for ticket snatching publicly discloses secrets !, Python secrets

Many software programs on the market for ticket snatching should be very familiar to everyone, but few people study how to implement the software, so it is mysterious and actually very simple. Next we will use Python to simulate the ticket snatching program and reveal to you how the ticket snatching is going.

This code is for reference only and is mainly used for communication and commercial purposes.

The Code is as follows. You can change it to your 12306 username account:

#-*-Coding: UTF-8-*-from splinter. browser import Browserfrom time import sleepimport tracebackimport time, sysclass huoche (object ): "docstring for huoche" driver_name = ''executable_path ='' username = u "xxx@qq.com" passwd = u "xxxx" starts = u "% u4E0A % u6D77 % 2 CSHH "ends = u" % u592A % u539F % 2 CTYV "dtime = u" 2018-01-19 "order = 0 users = [u" xxx ", u "xxx"] xb = u "second-class seat" pz = u "adult ticket" ticket_url = "https: // kyf 201712306.cn/otn/leftticket/init "login_url =" https://kyfw.12306.cn/otn/login/init "initmy_url =" https://kyfw.12306.cn/otn/index/initMy12306 "buy =" https://kyfw.12306.cn/otn/confirmPassenger/initDc "def _ init _ (self): self. driver_name = 'chrome 'self.exe cutable_path ='/usr/local/bin/chromedriver 'def login (self): self. driver. visit (self. login_url) self. driver. fill ("loginUserDTO. user_name ", self. userna Me) # sleep (1) self. driver. fill ("userDTO. password ", self. passwd) print u "waiting for verification code... "while True: if self. driver. url! = Self. initmy_url: sleep (1) else: break def start (self): self.driver?browser(driver_name=self.driver_name,executable_path=self.exe cutable_path) self. driver. driver. set_window_size (1400,100 0) self. login () # sleep (1) self. driver. visit (self. ticket_url) try: print u "ticket purchase page starts... "self. driver. cookies. add ({"_ jc_save_fromStation": self. starts}) self. driver. cookies. add ({"_ jc_save_toStation": self. ends}) self. Driver. cookies. add ({"_ jc_save_fromDate": self. dtime}) self. driver. reload () count = 0 if self. order! = 0: while self. driver. url = self. ticket_url: self. driver. find_by_text (u "query "). click () count + = 1 print u "loop click query... "% count # sleep (1) try: self. driver. find_by_text (u "Reservation") [self. order-1]. click () Cancel t Exception as e: print e print u "has not started booking" continue else: while self. driver. url = self. ticket_url: self. driver. find_by_text (u "query "). click () count + = 1 print u "loop click query... "% count # sleep (0.8) try: for I in self. driver. find_by_text (u "Reservation"): I. click () sleep (1) failed t Exception as e: print e print u "haven't started booking % s" % count continue print u "Start booking... "# sleep (3) # self. driver. reload () sleep (1) print U' start to select the user... 'for user in self. users: self. driver. find_by_text (user ). last. click () print u "Submit order... "sleep (1) # self. driver. find_by_text (self. pz ). click () # self. driver. find_by_id (''). select (self. pz) # sleep (1) # self. driver. find_by_text (self. xb ). click () # sleep (1) self. driver. find_by_id ('submitorder _ id '). click () # print u "to start seat selection... "# self. driver. find_by_id ('1d '). last. click () # self. driver. find_by_id ('1f '). last. click () sleep (1.5) print u "to confirm seat selection... "self. driver. find_by_id ('qr _ submit_id '). click () failed t Exception as e: print eif _ name _ = '_ main _': huoche = huoche () huoche. start ()

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.