直播app开发搭建,图形和短信验证码的自动识别获取
selenuim操作
driver=webdriver.Chrome()
driver.get("https://locvps.wenjingnetwork.com/page.aspx?c=reg")
driver.implicitly_wait(10)#设置超时时间
driver.find_element_by_name("uname").send_keys()
driver.find_element_by_name("ps").send_keys()
driver.find_element_by_name("ps1").send_keys()
driver.find_element_by_name("email").send_keys(")#邮箱输入
driver.find_element_by_name("tel").send_keys()#电话号码输入
driver.find_element_by_id("btn_smsvcode").click()#短信验证码发送
driver.find_element_by_name("vcode_graph").send_keys()#图形验证码输入
driver.find_element_by_name("vcode_graph").send_keys()
def isElementPresent():
# 从selenium.common.exceptions 模块导入 NoSuchElementException类
from selenium.common.exceptions import NoSuchElementException
try:
element = driver.find_element_by_xpath("/html/body/div[7]").get_attribute("style")
# 原文是except NoSuchElementException, e:
except NoSuchElementException as e:
# 打印异常信息
print(e)
# 发生了NoSuchElementException异常,说明页面中未找到该元素,返回False
return False
else:
# 没有发生异常,表示在页面中找到了该元素,返回True
return True
while isElementPresent():#图形验证码识别循环
driver.find_element_by_xpath("/html/body/div[7]/div[1]/button").click()
driver.find_element_by_id("btn_smsvcode").click() # 短信验证码发送
msg_test = imag_code()
driver.find_element_by_name("vcode_graph").send_keys() # 图形验证码输入
driver.find_element_by_name("vcode_graph").send_keys(R)
driver.find_element_by_xpath("//*[@id='mainContent']/div[1]/form/div[1]/p[6]/input[1]").send_keys()#短信验证码输入
driver.find_element_by_id("chkAgreeService").click()#勾选框
driver.find_element_by_xpath("//*[@id='mainContent']/div[1]/form/div[2]/p[2]/input[1]").click()
图形验证码识别
driver.save_screenshot('v_code.png') # 先把整个页面截图下来
element = driver.find_element_by_id('sccImg') # 定位验证码元素
print("验证码元素位置:", element.location)
print("验证码元素尺寸:", element.size)
left = element.location['x']
top = element.location['y']
right = element.location['x'] + element.size['width']
bottom = element.location['y'] + element.size['height']
im = PIL.Image.open('v_code.png')
im = im.crop((left, top, right, bottom))
# im.show()
image=pytesseract.image_to_string(im)
短信验证码自动获取
url = "查看api文档"
response = requests.get(url)
print(response.text)
以上就是直播app开发搭建,图形和短信验证码的自动识别获取, 更多内容欢迎关注之后的文章
标签:自动识别,keys,app,driver,验证码,send,element,find From: https://www.cnblogs.com/yunbaomengnan/p/17371068.html