国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

python自動(dòng)化調(diào)用百度api解決驗(yàn)證碼

瀏覽:2日期:2022-06-22 15:47:51

自動(dòng)化測試驗(yàn)證碼登陸的三種解決方式

1,找開發(fā)關(guān)閉驗(yàn)證碼2,找開發(fā)設(shè)置萬能驗(yàn)證碼3,使用第三方接口識(shí)別驗(yàn)證?不能100%識(shí)別,比自己搭建的ocr識(shí)別的識(shí)別率高很多

具體講的就是第三種-調(diào)用百度云識(shí)別驗(yàn)證碼:

from selenium import webdriverfrom PIL import Imageimport base64import requestsimport timedef baidu_api(Verification_code, AK, SK):#Verification_code驗(yàn)證碼路徑,AK,SK百度云的身份識(shí)別碼 chrome.get_screenshot_as_file(’reg.png’) # 獲取登陸頁面的圖片 code_img = chrome.find_element_by_xpath(Verification_code) # 找到驗(yàn)證碼圖片的位置 img = Image.open(’reg.png’)# 保存圖片 c_img = img.crop((code_img.location[’x’], code_img.location[’y’], code_img.location[’x’] + code_img.size[’width’], code_img.location[’y’] + code_img.size[’height’])) # 截取驗(yàn)證碼圖片 c_img.save(’reg_code.png’) host = ’https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&’ ’client_id=’+AK+’&’ ’client_secret=’+ SK response = requests.get(host) token = response.json()[’access_token’] request_url = 'https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic' f = open(’reg_code.png’, ’rb’)# 二進(jìn)制方式打開圖片文件 img = base64.b64encode(f.read()) params = {'image': img} access_token = token request_url = request_url + '?access_token=' + access_token headers = {’content-type’: ’application/x-www-form-urlencoded’} response = requests.post(request_url, data=params, headers=headers) dict_a = response.json()[’words_result’] if response:dict_a = eval(str(dict_a)[1:-1])#數(shù)據(jù)類型的格式轉(zhuǎn)換dict_a = dict(dict_a)#轉(zhuǎn)化為字典類型dict_a = dict_a[’words’]dict_a = ''.join(dict_a.split()) # 使用一個(gè)空字符串合成列表內(nèi)容生成新的字符串dict_a = dict_a.lower()#把大寫字母改為小寫字母return dict_a else:chrome.refresh()chrome = webdriver.Chrome()#瀏覽器實(shí)例化chrome.maximize_window()#最大化瀏覽器chrome.get(’自己登陸的網(wǎng)址’)test = baidu_api(Verification_code, AK, SK)#返回識(shí)別的驗(yàn)證碼chrome = webdriver.Chrome()print(test)#驗(yàn)證碼

百度云AK,SK的獲取:進(jìn)入:百度云點(diǎn)擊立即使用——進(jìn)行登陸——實(shí)名認(rèn)證。

python自動(dòng)化調(diào)用百度api解決驗(yàn)證碼

按著自己的需求選著,免費(fèi)的基本上就夠用了

python自動(dòng)化調(diào)用百度api解決驗(yàn)證碼

這就是自己的AK和SK

然后寫入在代碼里給AK和SK就行了

到此這篇關(guān)于python自動(dòng)化調(diào)用百度api解決驗(yàn)證碼的文章就介紹到這了,更多相關(guān)python調(diào)用百度api驗(yàn)證碼內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: 百度 Python
相關(guān)文章:
主站蜘蛛池模板: 仙游县| 卢龙县| 阳原县| 若尔盖县| 云安县| 巢湖市| 潼关县| 当涂县| 郴州市| 缙云县| 肃南| 论坛| 西和县| 宜宾县| 城固县| 竹北市| 大渡口区| 德清县| 苗栗县| 沈阳市| 涞水县| 陵川县| 河南省| 徐汇区| 颍上县| 孙吴县| 丰镇市| 子洲县| 仁布县| 都江堰市| 治县。| 苗栗市| 名山县| 文安县| 吉水县| 临潭县| 青川县| 十堰市| 额尔古纳市| 龙南县| 天等县|