日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python识别12306验证码_Python3.4实现的12306最新验证码识别

發(fā)布時間:2024/9/18 python 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python识别12306验证码_Python3.4实现的12306最新验证码识别 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

下面是編程之家 jb51.cc 通過網(wǎng)絡(luò)收集整理的代碼片段。

編程之家小編現(xiàn)在分享給大家,也給大家做個參考。

import ssl

import json

from PIL import Image

import urllib

import re

import urllib.request as urllib2

if hasattr(ssl,'_create_unverified_context'):

ssl.create_default_context = ssl._create_unverified_context

UA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/41.0.2272.89 Safari/537.36"

pic_url = "https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew?module=login&rand=sjrand&0.21191171556711197"

def get_img():

resp = urllib2.urlopen(pic_url)

raw = resp.read()

with open('./tmp.jpg','wb') as fp:

fp.write(raw)

return Image.open('./tmp.jpg')

def get_sub_img(im,x,y):

assert 0 <= x <= 3

assert 0 <= y <= 2

WITH = HEIGHT = 68

left = 5 + (67 + 5) * x

top = 41 + (67 + 5) * y

right = left + 67

bottom = top + 67

return im.crop((left,top,right,bottom))

def baidu_stu_lookup(im):

url = "http://stu.baidu.com/n/image?fr=html5&needRawImageUrl=true&id=WU_FILE_0&name=233.png&type=image%2Fpng&lastModifiedDate=Mon+Mar+16+2015+20%3A49%3A11+GMT%2B0800+(CST)&size="

im.save("./query_temp_img.png")

raw = open("./query_temp_img.png",'rb').read()

url = url + str(len(raw))

req = urllib2.Request(url,raw,{'Content-Type': 'image/png','User-Agent': UA})

resp_url = urllib2.urlopen(req).read()

url = "http://stu.baidu.com/n/searchpc?queryImageUrl=" + urllib2.quote(resp_url)

req = urllib2.Request(url,headers={'User-Agent': UA})

resp = urllib2.urlopen(req)

html = resp.read().decode()

return baidu_stu_html_extract(html)

def baidu_stu_html_extract(html):

pattern = re.compile(r"keywords:'(.*?)'")

matches = pattern.findall(html)

if not matches:

return '[UNKOWN]'

json_str = matches[0]

json_str = json_str.replace('\\x22','"').replace('\\\\','\\')

result = [item['keyword'] for item in json.loads(json_str)]

return '|'.join(result) if result else '[UNKOWN]'

if __name__ == '__main__':

im = get_img()

for y in range(2):

for x in range(4):

im2 = get_sub_img(im,y)

result = baidu_stu_lookup(im2)

print((y,x),result)

以上是編程之家(jb51.cc)為你收集整理的全部代碼內(nèi)容,希望文章能夠幫你解決所遇到的程序開發(fā)問題。

如果覺得編程之家網(wǎng)站內(nèi)容還不錯,歡迎將編程之家網(wǎng)站推薦給程序員好友。

總結(jié)

以上是生活随笔為你收集整理的python识别12306验证码_Python3.4实现的12306最新验证码识别的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。