资源简介
通过python在12306非常完整的下单购票程序、自动识别验证码登陆,有兴趣且有python基础的朋友可下载。下载后请读代码,创配置文件方可运行。由于最新更新的cookies存在,所以需要提前使用谷歌浏览器访问12306官网才可使用该脚本。童叟无欺承诺后续跟新及周五定时查看留言问题,对得起你的积分
代码片段和文件信息
# -*- coding: utf-8 -*-
import json requests ssl os datetime urllib.parse sys sqlite3time
from win32.win32crypt import CryptUnprotectData
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
ssl._create_default_https_context = ssl._create_unverified_context
from requests.packages.urllib3.exceptions import InsecureRequestWarning
# 禁用安全请求警告
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
# 构建SESSION
session = requests.session()
session.verify = False
header = {
‘Host‘: ‘kyfw.12306.cn‘
‘Referer‘: ‘https://kyfw.12306.cn/otn/resources/login.html‘
‘User-Agent‘: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML like Gecko) Chrome/74.0.3729.169 Safari/537.36‘
}
def ma():
import re
######查找对应网站的cookies
host = ‘.12306.cn‘
cookiepath = os.environ[
‘LOCALAPPDATA‘] + r“\Google\Chrome\User Data\Default\Cookies“ ###C:\Users\xxxy用户\AppData\Local\Google\Chrome\User Data\Defaul
sql = “select host_keynameencrypted_value from cookies where host_key=‘%s‘“ % host
with sqlite3.connect(cookiepath) as conn:
cu = conn.cursor()
cookies = {name: CryptUnprotectData(encrypted_value)[1].decode() for host_key name encrypted_value in
cu.execute(sql).fetchall()}
# print(cookies)
EXP = cookies[‘RAIL_EXPIRATION‘] ###打印对应的cookies值
RA = cookies[‘RAIL_DEVICEID‘] ###打印对应的cookies值
print(RA)
# session.cookies[‘RAIL_EXPIRATION‘] =EXP
session.cookies[‘RAIL_DEVICEID‘] = RA
#############################获取验证码图片########################
import base64configparser
tu = “https://kyfw.12306.cn/passport/captcha/captcha-image64?login_site=E&module=login&rand=sjrand&1560324897958&callback=jQuery191046088946883591486_1560324572504&_=1560324572506“
req = session.get(tu headers=header)
req = req.text
img_base64 = re.findall(r‘“image“:“(.*?)“‘ req)[0]
img_encode = base64.b64decode(img_base64)
with open(‘tu.jpg‘ ‘wb‘) as f:
f.write(img_encode)
##########################用户输入#############################
today = datetime.date.today()
config = configparser.ConfigParser()
path = “12306.txt“
config.read(path encoding=“utf-8-sig“)
user = config.get(“info“ “user“)
password = config.get(“info“ “password“)
cf = config.get(“info“ “cf“)
zd = config.get(“info“ “zd“)
time = config.get(“info“ “time“)
mail = config.get(“info“ “mail“)
stat_time = config.get(“info“ “cartime“)
stat_time = stat_time+“:“
zuo = config.get(“info“ “zuo“)
people = config.get(“info“ “people“)
##########################验证码输入#############################
dcit = {‘1‘: ‘4152‘ ‘2‘: ‘11050‘ ‘3‘: ‘17850‘ ‘4‘: ‘25552‘
‘5‘: ‘41117 ‘ ‘6‘: ‘111122‘ ‘7‘: ‘182125‘ ‘8‘: ‘252117‘}
url = “http://shell.teachx.cn:12306/predict“
- 上一篇:老唐的1——python数据分析与机器学习实战
- 下一篇:百度搜索批量爬取真实URL
相关资源
- python实现SGBM图像匹配算法
- python实现灰度直方图均衡化
- scrapy_qunar_one
- Python学习全系列教程永久可用
- python简明教程.chm
- 抽奖大转盘python的图形化界面
- 双边滤波器实验报告及代码python
- python +MYSQL+HTML实现21蛋糕网上商城
- Python-直播答题助手自动检测出题搜索
- OpenCV入门教程+OpenCV官方教程中文版
- Python 串口工具源码+.exe文件
- Python开发的全栈股票系统.zip
- Python操作Excel表格并将其中部分数据写
- python书籍 PDF
- 利用python绘制散点图
- python+labview+No1.vi
- 老男孩python项目实战
- python源码制作whl文件.rar
- python3.5可用的scipy
- PYTHON3 经典50案例.pptx
- 计算机科学导论-python.pdf
- python模拟鼠标点击屏幕
- windows鼠标自动点击py脚本
- 鱼c小甲鱼零基础学python全套课后题和
- Python 练习题100道
- Practical Programming 2nd Edition
- wxPython Application Development Cookbook
- python 3.6
- Python 3.5.2 中文文档 互联网唯一CHM版本
- python3.5.2.chm官方文档
评论
共有 条评论