12306 登录验证数据下载(未标定)

数据包括切割好的验证文字信息和验证图片块

在这里插入图片描述
在这里插入图片描述

word_patch_message{
	"number":2930,
	"shape": (25,175,3),
	"Deduplication":true
}
image_patch_message{
	"number":23593,
	"shape" :(67,67,3),
	"Deduplication":true
}

数据下载地址
================================================
Sorry 服务器欠费已停用,现给出爬虫代码及切图代写
================================================
1、爬取验证图片

#coding:u8
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
import requests
import base64
import re
import time
import os
import _thread


def getImage(name):
	login_url="https://kyfw.12306.cn/otn/resources/login.html"
	driver = webdriver.Chrome()
	driver.get(login_url)
	count=0
	while 1:
		count+=1
		if not os.path.exists(name):
			os.mkdir(name)		
		driver.find_element_by_class_name("login-hd-account").click()
		try:	
			time.sleep(2)
			img_element =WebDriverWait(driver, 100).until(
				EC.presence_of_element_located((By.ID, "J-loginImg"))
			)
			base64_str=img_element.get_attribute("src").split(",")[-1]
			imgdata=base64.b64decode(base64_str)
			pname=os.path.join("verify",name+str(count)+".jpg")
			print(pname)
			with open(pname,'wb') as file:
				file.write(imgdata)
		except Exception as e:
			print(u"网络开小差,请稍后尝试")	
		
		driver.refresh()
print("start")
try:
	_thread.start_new_thread(getImage,("THREAD-1",))
	_thread.start_new_thread(getImage,("THREAD-2",))	
	_thread.start_new_thread(getImage,("THREAD-3",))
	_thread.start_new_thread(getImage,("THREAD-4",))	
except Exception as e:
	print("启动失败")
while 1:
   pass

爬虫开了4个线程,将验证图片放入4个文件夹中,请自行归并到一个文件夹下,供切图使用
2、切图

#coding:u8
import cv2
import os
if not os.path.exists("12306_dataset_obj"):
	os.mkdir("12306_dataset_obj")
if not os.path.exists("12306_dataset_word"):
	os.mkdir("12306_dataset_word")	
for batch,file_name in enumerate(os.listdir("verify")):

	print(u"处理第{:>9}张图".format(batch+1))
	im=cv2.imread("verify/{}".format(file_name),1)

	patch=[
		im[0:25,120:290],
		im[41:108,5:72],
		im[41:108,77:144],
		im[41:108,149:216],
		im[41:108,221:288],
		im[113:180,5:72],
		im[113:180,77:144],
		im[113:180,149:216],
		im[113:180,221:288]
		]
	
	for i,item in enumerate(patch):
		if i is not 0:
			cv2.imwrite("12306_dataset_obj/{}.jpg".format(batch*8+i),item)
		else:
			cv2.imwrite("12306_dataset_word/{}.jpg".format(batch+1),item)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值