广州外贸建网站,代理什么产品好做挣钱,制作 网站导航 下拉菜单,桥头东莞网站建设市场上很多火车票抢票软件大家应该非常熟悉#xff0c;但很少有人研究具体是怎么实现的#xff0c;所以觉得很神秘#xff0c;其实很简单。下面使用Python模拟抢票程序#xff0c;给大家揭秘抢票到底是怎么回事。该代码仅供参考#xff0c;主要用于大家沟通交流#xff0…市场上很多火车票抢票软件大家应该非常熟悉但很少有人研究具体是怎么实现的所以觉得很神秘其实很简单。下面使用Python模拟抢票程序给大家揭秘抢票到底是怎么回事。该代码仅供参考主要用于大家沟通交流禁止用于商业用途。具体代码如下可以修改成自己的12306用户名账号# -*- coding: utf-8 -*-from splinter.browser import Browserfrom time import sleepimport tracebackimport time, sysclass huoche(object):docstring for huochedriver_nameexecutable_pathusername uxxxqq.compasswd uxxxxstarts u%u4E0A%u6D77%2CSHHends u%u592A%u539F%2CTYVdtime u2018-01-19order 0users [uxxx,uxxx]xb u二等座pzu成人票ticket_url https://kyfw.12306.cn/otn/leftTicket/initlogin_url https://kyfw.12306.cn/otn/login/initinitmy_url https://kyfw.12306.cn/otn/index/initMy12306buyhttps://kyfw.12306.cn/otn/confirmPassenger/initDcdef __init__(self):self.driver_namechromeself.executable_path/usr/local/bin/chromedriverdef login(self):self.driver.visit(self.login_url)self.driver.fill(loginUserDTO.user_name, self.username)# sleep(1)self.driver.fill(userDTO.password, self.passwd)print u等待验证码...while True:if self.driver.url ! self.initmy_url:sleep(1)else:breakdef start(self):self.driverBrowser(driver_nameself.driver_name,executable_pathself.executable_path)self.driver.driver.set_window_size(1400, 1000)self.login()# sleep(1)self.driver.visit(self.ticket_url)try:print u购票页面开始...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()count0if self.order!0:while self.driver.urlself.ticket_url:self.driver.find_by_text(u查询).click()count 1print u循环点击查询... % count# sleep(1)try:self.driver.find_by_text(u预订)[self.order - 1].click()except Exception as e:print eprint u还没开始预订continueelse:while self.driver.url self.ticket_url:self.driver.find_by_text(u查询).click()count 1print u循环点击查询... % count# sleep(0.8)try:for i in self.driver.find_by_text(u预订):i.click()sleep(1)except Exception as e:print eprint u还没开始预订 %s %countcontinueprint u开始预订...# sleep(3)# self.driver.reload()sleep(1)print u开始选择用户...for user in self.users:self.driver.find_by_text(user).last.click()print u提交订单...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开始选座...# self.driver.find_by_id(1D).last.click()# self.driver.find_by_id(1F).last.click()sleep(1.5)print u确认选座...self.driver.find_by_id(qr_submit_id).click()except Exception as e:print eif __name__ __main__:huochehuoche()huoche.start()以上就是本文的全部内容希望对大家的学习有所帮助也希望大家多多支持。