forked from zhaipro/easy12306
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yifuda
committed
Nov 18, 2018
1 parent
94dfe31
commit 7974523
Showing
7 changed files
with
83 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,3 +52,5 @@ docs/_build/ | |
|
||
# PyBuilder | ||
target/ | ||
|
||
*.jpg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,30 @@ | ||
# -*- coding: cp936 -*- | ||
# 功能:抓取验证码 | ||
# 并存放到img目录下 | ||
# 文件名为图像的MD5 | ||
import urllib2 | ||
#! env python3 | ||
# coding: utf-8 | ||
# 功能:抓取验证码 | ||
# 并存放到img目录下 | ||
# 文件名为图像的MD5 | ||
import hashlib | ||
import time | ||
# hack CERTIFICATE_VERIFY_FAILED | ||
# https://github.com/mtschirs/quizduellapi/issues/2 | ||
import ssl | ||
if hasattr(ssl, '_create_unverified_context'): | ||
ssl._create_default_https_context = ssl._create_unverified_context | ||
|
||
import requests | ||
|
||
import utils | ||
|
||
|
||
def download_img(): | ||
pic_url = 'https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew?module=login&rand=sjrand&0.21191171556711197' | ||
resp = urllib2.urlopen(pic_url) | ||
raw = resp.read() | ||
fn = hashlib.md5(raw).hexdigest() | ||
with open("img/%s.jpg" % fn, 'wb') as fp: | ||
fp.write(raw) | ||
url = 'https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew?module=login&rand=sjrand' | ||
response = requests.get(url) | ||
fn = hashlib.md5(response.content).hexdigest() | ||
with open(f'img/{fn}.jpg', 'wb') as fp: | ||
fp.write(response.content) | ||
|
||
|
||
if __name__ == '__main__': | ||
utils.mkdir('img') | ||
i = 0 | ||
while True: | ||
try: | ||
# time.sleep(1) # 这里根本不需要等待 | ||
download_img() | ||
i += 1 | ||
print i | ||
print(i) | ||
except: | ||
print 'error' | ||
print('error') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
requests | ||
sklearn | ||
opencv-python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,27 @@ | ||
# -*- coding: cp936 -*- | ||
# coding: utf-8 | ||
import os | ||
import shutil | ||
import sys | ||
|
||
import utils | ||
|
||
result_fn = sys.argv[1] | ||
classify_fn = sys.argv[2] | ||
|
||
# 用于统计有多少聚类中心是有样本的 | ||
utils.mkdir(classify_fn) | ||
|
||
# 用于统计有多少聚类中心是有样本的 | ||
s = set() | ||
fp = open(result_fn) | ||
for line in fp: | ||
(fn, classify) = line.strip().split(' ') | ||
s.add(int(classify)) | ||
fp.close() | ||
print len(s) | ||
fn, classify = line.split() | ||
s.add(classify) | ||
print(len(s)) | ||
|
||
# 将聚类后的样本复制并使用聚类结果命名 | ||
fp = open(result_fn) | ||
# 将聚类后的样本复制并使用聚类结果命名 | ||
fp.seek(0) | ||
for idx, line in enumerate(fp): | ||
(fn, classify) = line.strip().split(' ') | ||
shutil.copy(os.path.join('ocr', fn), '%s/%s(%d).jpg' % (classify_fn, classify, idx)) | ||
fn, classify = line.strip().split() | ||
src = os.path.join('ocr', fn) | ||
dst = f'{classify_fn}/{classify}({idx}).jpg' | ||
shutil.copy(src, dst) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# coding: utf-8 | ||
import os | ||
|
||
|
||
def mkdir(path): | ||
if not os.path.isdir(path): | ||
os.mkdir(path) |