标签:12306 验证码
# -*- coding:utf-8 -*-
import urllib
import urllib2
import ssl
import os
import time
ssl._create_default_https_context = ssl._create_unverified_context
url=‘https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew?module=login&rand=sjrand‘
user_agent=‘Mozilla/4.0 (Mozilla/5.0 (Windows NT 6.1; WOW64))‘
headers={‘User-Agent‘:user_agent}
number=11306
while True:
try:
request=urllib2.Request(url,headers=headers)
response=urllib2.urlopen(request)
name=‘D:/pic/‘+str(number)+‘.jpg‘
with open(name,"wb") as image:
image.write(response.read())
number=number+1
time.sleep(0.5)
print name
except urllib2.URLError,e:
if hasattr(e,"code"):
print e.code
if hasattr(e,"reason"):
print e.reason
print "end"
本文出自 “叶子” 博客,请务必保留此出处http://luoqiu.blog.51cto.com/2198651/1650740
标签:12306 验证码
原文地址:http://luoqiu.blog.51cto.com/2198651/1650740