百度api mac地址提取

# encoding:utf-8import requestsimport base64import pprintimport redef get_token(): host = ‘https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&‘ ‘client_id=client_secret=‘ response = requests.get(host) if response: return response.json()def all_text(): """ 通用文字识别 :return: """ request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic" # 二进制方式打开图片文件 with open(‘mac.jpg‘, ‘rb‘) as f: img = base64.b64encode(f.read()) params = {"image": img} access_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) if response: return response.json()if __name__ == ‘__main__‘: # pprint.pprint(get_token()) a = all_text() b = str(a[‘words_result‘]) print(b) print(re.search(r‘([A-Fa-f0-9]{2}-){5}[A-Fa-f0-9]{2}‘, b))

相关文章