登陆识别验证码

来源:2-15 showapiRequest解决图片验证码识别

AnberYang

2019-03-01

代码没有报错 却识别不了验证码

from selenium import webdriver
from PIL import Image
from ShowapiRequest import ShowapiRequest
import time

driver = webdriver.Chrome()
driver.get(“https://zwdtuser.sh.gov.cn/uc/login/login.jsp”)
time.sleep(5)

def get_code_image(file_name):
driver.save_screenshot(file_name)
code_element = driver.find_element_by_id(“img”)
print(code_element.location)#坐标定位验证码位置(“x”:123,“y”:345)
left = code_element.location[‘x’]
top = code_element.location[‘y’]
right = code_element.size[‘width’]+left
height = code_element.size[‘height’]+top
im = Image.open(file_name)
img = im.crop((left,top,right,height))
img.save(file_name)

def code_online(file_name):
r = ShowapiRequest(“http://route.shouapi.com/184-5”, “id”, “ccad”)#账个人户和密码隐藏
r.addBodyPara(“img_base64”, “”)
r.addBodyPara(“typeId”,“35”)
r.addBodyPara(“convert_to_jpg”,“0”)
r.addBodyPara(“image”,file_name)
res = r.post()
text = res.json()[‘showapi_res_body’][‘Result’]
print(res.text)
return text
driver.close()

写回答

1回答

威哥V5

2019-03-01

已解决。

//img.mukewang.com/szimg/5c79071c0001bf0a10060882.jpg

low 代码 没问题了

0
2
Mushishi
回复
威哥V5
哈哈,这个只是一种解决方案。叫你们如何解决遇见类似问题怎么解决。
2019-03-01
共2条回复

Selenium3与Python3实战Web自动化测试框架

打破无项目经验、无框架经验瓶颈,实战Web自动化测试框架!

1883 学习 · 1093 问题

查看课程