12306自动抢票及自动识别验证码功能(三)--分流

这几天研究了下12306分流,之前12306pass不停切换CDN来刷新数据,这样减少缓存时间,写了个脚本从官网上抓了一批CDN服务器来测试

验证cdn脚本:

#! /usr/bin/env python3
# -*- coding:utf-8 -*-

import os,requests,time,re
import sys,codecs,json
requests.packages.urllib3.disable_warnings(requests.packages.urllib3.exceptions.InsecureRequestWarning)
#self.session = requests.session()
headers = {
    'Host': 'kyfw.12306.cn',
    'Origin': 'https://kyfw.12306.cn',
    'X-Requested-With': 'XMLHttpRequest',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'Referer': 'https://kyfw.12306.cn/otn/login/init',
    'Accept': '*/*',
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'zh-CN,zh;q=0.8',
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36',
}


#读取iptxt文件
def loadtxt():
    ysyurl = "{0}/iprange.txt".format(sys.path[0])
    f = open(ysyurl)  # 返回一个文件对象
    realips = []
    line = f.readline()  # 调用文件的 readline()方法
    while line:
        line = f.readline()
        line = re.sub('\n', '', line)
        realips.append(line)
    f.close()
    return realips


realips=loadtxt()
curnum=0
for ip in realips:
    try:
        url="https://{0}/otn/".format(ip)
        print(url)
        response = requests.get(url=url,headers=headers, timeout=5, verify=False)
        print(response.headers)
        if (response.status_code==200):
            curnum += 1
            print(curnum)
        time.sleep(1.5)
    except Exception as e:
        print(e)

目前基本实现了12306pass的功能,判断了下,有时候可能链接超时会自动转换CDN

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值