< a href="https://github.com/%E5%B0%8F%E7%9A%AE%E6%B5%A9"> Fork me on GitHub

selenium和百度ai智能图像识别

<!doctype html>

selenium和百度ai智能图像识别

selenium和百度ai智能图像识别

在百度ai图像识别中创建应用,获取工具码

from selenium import webdriver
import time

from aip import AipOcr

def initial():
#ai工具码
""" 初始化连接 """
APP_ID = '16611607'
API_KEY = 'wAIXfXOUS8ztLa4FrK3rZex1'
SECRET_KEY = '3b8nvjSGUZq0LPC18VVAizKYRBbny6Mq'
return AipOcr(APP_ID, API_KEY, SECRET_KEY)

def get_file_content(filePath):
""" 读取图片 """
print(333333333333333, filePath)
with open(filePath, 'rb') as f:
return f.read()

def get_file_content(filePath):
"""读取图片"""
print(333333333, filePath)
with open(filePath,'rb') as f:
return f.read()

def selenium_msg():
driver = webdriver.Chrome()
try:
driver.get('https://pythonav.com/login/')
time.sleep(1)
driver.find_element_by_id('id_username').send_keys("guo")
time.sleep(1)
driver.find_element_by_id('id_password').send_keys("123")

    image = driver.find_element_by_id(&#39;image_code&#39;)

    file_path = &quot;b.png&quot;
    image.screenshot(file_path)

    #百度ai
    client = initial()
    image = get_file_content(file_path)
    print(4444444, image)
    res1 = client.basicGeneral(image)
    print(res1)
    driver.find_element_by_id(&#39;id_code&#39;).send_keys(res1[&#39;words_result&#39;][0][&#39;words&#39;])
    time.sleep(2)
    driver.find_element_by_class_name(&#39;btn-primary&#39;).click()
finally:
    time.sleep(5)
    driver.quit()

if name == 'main':
selenium_msg()

 

posted @ 2020-01-09 21:25  赌徒!  阅读(317)  评论(0编辑  收藏  举报