久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

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

python自動化調(diào)用百度api解決驗證碼

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

自動化測試驗證碼登陸的三種解決方式

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

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

from selenium import webdriverfrom PIL import Imageimport base64import requestsimport timedef baidu_api(Verification_code, AK, SK):#Verification_code驗證碼路徑,AK,SK百度云的身份識別碼 chrome.get_screenshot_as_file(’reg.png’) # 獲取登陸頁面的圖片 code_img = chrome.find_element_by_xpath(Verification_code) # 找到驗證碼圖片的位置 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’])) # 截取驗證碼圖片 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()) # 使用一個空字符串合成列表內(nèi)容生成新的字符串dict_a = dict_a.lower()#把大寫字母改為小寫字母return dict_a else:chrome.refresh()chrome = webdriver.Chrome()#瀏覽器實例化chrome.maximize_window()#最大化瀏覽器chrome.get(’自己登陸的網(wǎng)址’)test = baidu_api(Verification_code, AK, SK)#返回識別的驗證碼chrome = webdriver.Chrome()print(test)#驗證碼

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

python自動化調(diào)用百度api解決驗證碼

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

python自動化調(diào)用百度api解決驗證碼

這就是自己的AK和SK

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

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

標(biāo)簽: 百度 Python
相關(guān)文章:
主站蜘蛛池模板: 莱州市| 长汀县| 英超| 仲巴县| 桐乡市| 泰州市| 柳林县| 桐城市| 汾西县| 永平县| 牟定县| 托克托县| 泰来县| 德化县| 察雅县| 凉城县| 集贤县| 沙坪坝区| 墨脱县| 资源县| 新龙县| 北流市| 黑河市| 青川县| 博乐市| 邓州市| 临城县| 巩义市| 永吉县| 江北区| 皋兰县| 南部县| 虞城县| 东阿县| 宜都市| 西乌珠穆沁旗| 武清区| 平陆县| 庐江县| 太康县| 揭阳市|