代码展示:

import urllib.request as requestimport http.cookiejar as cookiejarimport reimport osimport smtplibfrom email.mime.text import MIMETextimport timeuser = '' #登陆邮箱pwd = ''#邮箱密码to = [''] #发送的邮箱with open('D:\Python源码\city.txt','r') as f:a = f.read()station = re.compile(u'\w+:(.+?):(\w+):\d').findall(a)dic1 = {}for b in range(0, len(station)):dic1[station[b][0]] = station[b][1]def gethtml(geturl):cj = cookiejar.LWPCookieJar()cookiejarsupport = request.HTTPCookieProcessor(cj)opener = request.build_opener(cookiejarsupport,request.HTTPHandler)headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36','Host':'www.12306.cn','Referer':'http://www.12306.cn/opn/lcxxcx/init'}request.install_opener(opener)req = request.Request(url=geturl, headers=headers)html = request.urlopen(req).read().decode()return htmldef getstation(html):fromstation = re.compile(r'from_station_name":"(.+?)","').findall(html)tostation = re.compile(r'to_station_name":"(.+?)",').findall(html)startime =  re.compile(r'"start_time":"(.+?)"').findall(html)arrtime = re.compile(r'arrive_time":"(.+?)"').findall(html)lishi =  re.compile(r'"lishi":"(.+?)",').findall(html)webbuy = re.compile(r'"canWebBuy":"(.+?)').findall(html)startstation = re.compile(r'start_station_name":"(.+?)"').findall(html)endstation = re.compile(r'end_station_name":"(.+?)"').findall(html)ruanwo = re.compile((r'"rw_num":"(.+?)",')).findall(html)ruanzuo = re.compile((r'"rz_num":"(.+?)"')).findall(html)yingwo = re.compile(r'"yw_num":"(.+?)"').findall(html)ruanzuo = re.compile(r'"rz_num":"(.+?)"').findall(html)yingzuo = re.compile(r'"yz_num":"(.+?)"').findall(html)wuzuo = re.compile(r'"wz_num":"(.+?)"').findall(html)checi = re.compile(r'station_train_code":"(.+?)"').findall(html)datanum = re.compile((r'day_difference":"(.+?)"')).findall(html)erdengzuo = re.compile(r'ze_num":"(.+?)",').findall(html)num = range(0, len(yingwo))for i in num:try:if int(yingzuo[i]) != 0 or int(erdengzuo[i]) != 0 or int(wuzuo[i] !=0):     #Z108print(checi[i], '    二等座:', erdengzuo[i], '    硬座:', yingzuo[i],'   无座:',wuzuo[i])if yingwo[i] != '--' or yingzuo[i] != '无':msg=MIMEText('火车:'+fromstation[i]+' ->'+tostation[i] +'('+ checi[i]+ ')\n二等座:'+erdengzuo[i]+ '张;硬座:'+ yingzuo[i]+'张;无座:'+wuzuo[i]+ '张!快买去!\n网址:http://www.12306.cn/opn/lcxxcx/init')msg['Subject'] = '有票啦!'msg['From'] = usermsg['To'] = ','.join(to)s = smtplib.SMTP('smtp.qq.com', timeout = 30) #连接SMTP端口s.login(user,pwd)#登陆服务器s.sendmail(user,to,msg.as_string())s.close()print('发送成功')print('------------------------------------------------------------')except:continueprint('''''
--注:我这有个学习Python基地,里面有很多学习资料,感兴趣的+Q群:895817687
By:王小涛_同學
-------------------------------------------------------------- 欢迎使用!
--------------------------------------------------------------
''')
print ('请输入购票类型:(0为成人票   其他为学生票) ')
leixing = input()
print('请输入起点:')
qidian = input()
try:  if dic1[qidian]:  qidian = dic1[qidian]
except:  print('起点输入有误!')
print('请输入终点:')
zhongdian = input()
try:  if dic1[zhongdian]:  zhongdian = dic1[zhongdian]
except:  print('终点输入有误!')
print('请输入购票年份:')
year = input()+'-'
print('请输入购票月份:(2位)')
month = input()+'-'
print('请输入购票日期:(2位)')
date = input()
date = year + month + date  if leixing == 0:  geturl = 'http://www.12306.cn/opn/lcxxcx/query?purpose_codes=ADULT&queryDate='+date+'&from_station='+qidian+'&to_station='+ zhongdian
else:  geturl = 'http://www.12306.cn/opn/lcxxcx/query?purpose_codes=0X00&queryDate='+date+'&from_station='+qidian+'&to_station='+ zhongdian
while 1:  getstation(gethtml(geturl))  print('火车票监测中...')  time.sleep(300)  </pre>

python学习教程,12306火车票抢票系统相关推荐

  1. python学习:12306火车票抢票代码公开揭秘

    火车票抢票代码公开揭秘 市场上很多火车票抢票软件大家应该非常熟悉,但很少有人研究具体是怎么实现的,所以觉得很神秘,其实很简单.下面使用Python模拟抢票程序,给大家揭秘抢票到底是怎么回事. 该代码仅 ...

  2. 用python写12306系统_Python实现12306火车票抢票系统

    Python实现12306火车票抢票系统 来源:中文源码网    浏览: 次    日期:2019年11月5日 [下载文档:  Python实现12306火车票抢票系统.txt ] (友情提示:右键点 ...

  3. 基于python的火车票订票系统的设计与实现_Python实现12306火车票抢票系统

    Python实现12306火车票抢票系统效果图如下所示: 具体代码如下所示: import urllib.request as request import http.cookiejar as coo ...

  4. python抢票12306源码_Python实现12306火车票抢票系统

    Python实现12306火车票抢票系统效果图如下所示: 具体代码如下所示: import urllib.request as request import http.cookiejar as coo ...

  5. 基于python的12306自动抢票系统的设计与实现

    铁路售票系统12306网站作为一个广受人们的日常使用工具,受大极大的关注.铁路售票的管理者都主要考虑降低成本,提升售票服务满意度.一年一度的春运和节假日出行高峰期,给众多的出行群众者带来了极大的烦恼, ...

  6. android生成车票动效,Android项目源码功能齐全的12306火车票订票系统项目

    [实例简介] 本项目是一个基于安卓的12306火车票客户端项目源码,实现了早期的登录注册购票改签等功能.但是因为12306网站改版比换鞋垫还频繁,所以功能早就不能用了,不过项目提供了大部分功能的原来实 ...

  7. python github 12306 文贤平_GitHub - itsmartkit/12306-Ticket-Booking: 12306自动抢票系统(2020-01-10)...

    基于Python的12306自动订票系统 系统功能 1.余票监控:发现余票自动下单 2.自动打码:采用第三方免费接口/本地识别算法两种模式,自动验证图片验证码 3.小黑屋:发展有余票但是下单失败的车次 ...

  8. SpringBoot实现12306自动抢票系统

    写在前面 前段时间在浏览开源社区的时候,不小心看到一个 12306抢票 系统,一下就被吸引住了,然后就动力歪念头?,过年终于不用找黄牛了,哇哈哈哈,写了差不多一个星期,终于可以全自动抢票了,中间遇到的 ...

  9. 12306火车票抢票Python代码最新完整版发布,五一抢票就靠它了!

    语言版本:Python 1.自动登录12306并保持Cookie 2.自动实现抢购设置的某日期的某车次的票 3.攻克排队系统陷阱,避免进入排队系统 4.循环监控某车次的票,直到有票,自动抢购 5.抢票 ...

最新文章

  1. 逆变器的技术创新 让光伏电站更具发展前景
  2. 【转】android开发工具Eclipse,androidStudio,adt网盘下载--不错
  3. latex精要(1)-安装与helloworld
  4. 修改一个列表中的一个单词小技巧笔记
  5. Sping Cloud Eureka
  6. 构建DRM系统的重要基石——EME、CDM、AES、CENC和密钥
  7. 【c++进阶:c++ 顺序容器vector,string,deque,list,forward_list,array常用性质】
  8. 计算机专业女生的就业方向参考
  9. VS2013下使用cjson
  10. 野生前端的数据结构基础练习(2)——队列
  11. Letters比赛第六场1002 Babelfish解题报告
  12. 多图片上传,多文件上传。插件diyUpload.js
  13. 最全的LED电源解决方案 转载
  14. 天猫店群选哪个类目好?新手朋友做天猫无货源,性价比高的类目
  15. 【React】1332- 2022 年值得推荐的 React 库
  16. MPC-HC视频播放器
  17. ​mac安装CentOS虚拟机
  18. Vue 合同模板_【开源】后端开发也很容易上手的前端框架模板
  19. 阿里云自建k8s存储插件csi安装使用
  20. 实体-关系联合抽取:Incremental Joint Extraction of Entity Mentions and Relations

热门文章

  1. Spring 配置元数据
  2. 牛客题霸 SQL2 查找入职员工时间排名倒数第三的员工所有信息
  3. BugKuCTF WEB flag在index里
  4. CG CTF WEB php decode
  5. php视图,thinkPHP框架中视图的讲解(附代码)
  6. Java19-day10【标准输入输出流、字节字符打印流、对象序列化-反序列化流、serialVersionUIDtransient、Properties】
  7. 数据结构Java08【二叉平衡树(AVL)-概述、单旋转、双旋转】
  8. Java 进阶 ——2019 计划要读的书
  9. 后台开发人员面试内容——数据库(二)
  10. 彻底解决_OBJC_CLASS_$_某文件名, referenced from:问题