第一种方法读取验证码网址、打开本地路径、写入、输入验证码
url = 'https://www.myerong.com/verifyCode.action?t=1581504849970'
res = requests.get(url,verify=False)
print(res.content)
with open('a.jpg','wb') as fw:
fw.write(res.content)
第二种方法读取验证码网址、打开本地路径、写入、输入验证码
url = "https://www.myerong.com/verifyCode.action?t="+str(t)
headers = {
"Accept": "image/webp,image/apng,image/*,*/*;q=0.8",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Cookie": "Hm_lvt_7aa1ece4891bbe95ff97d9fc51c51c42=1581413386; Hm_lpvt_7aa1ece4891bbe95ff97d9fc51c51c42=1581413389",
"Host": "www.myerong.com",
"Pragma": "no-cache",
"Referer": "https://www.myerong.com/sites/pages/login/login.html",
"Sec-Fetch-Mode": "no-cors",
"Sec-Fetch-Site": "same-origin",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"
}
response =session.get(url,headers=headers,verify=False,timeout=5)
print(response.content)
with open('aa.jpg','wb') as fw:
fw.write(response.content)
url_02 = "https://www.myerong.com/auth.action?callback=jQuery112406286717784912901_1581413388276"
headers = {
"Accept":"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01",
"Accept-Encoding":"gzip, deflate, br",
"Accept-Language":"zh-CN,zh;q=0.9",
"Cache-Control":"no-cache",
"Connection":"keep-alive",
"Content-Length":"62",
"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",
"Cookie":"Hm_lvt_7aa1ece4891bbe95ff97d9fc51c51c42=1581413386; Hm_lpvt_7aa1ece4891bbe95ff97d9fc51c51c42=1581413389;
__session__key__register__code__=PmK8X263rekFTo1Q3Fonwg==",
"Host":"www.myerong.com",
"Origin":"https://www.myerong.com",
"Pragma":"no-cache",
"Referer":"https://www.myerong.com/sites/pages/login/login.html",
"Sec-Fetch-Mode":"cors",
"Sec-Fetch-Site":"same-origin",
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36",
"X-Requested-With":"XMLHttpRequest",
}
data = {
"method": "checkVerrifyCode",
"verrifyCode":input("输入验证码:"),
"subtime": str(t),
}
res =session.post(url_02,headers=headers,data=data,verify=False)
print(res.json())
第三种方读取验证码打码平台输入验证码
打码平台
file_name = 'aa.jpg'
yzmtype_mark=1001
headers_code = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
'Accept-Encoding': 'gzip, deflate',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0',
'Connection': 'keep-alive',
'Host': 'v1-http-api.jsdama.com',
'Upgrade-Insecure-Requests': '1'
}
files = {
'upload': (file_name, open(file_name, 'rb'), 'image/png')
}
data = {
'user_name': "名称*",
'user_pw': "密码",
'yzmtype_mark': 类型,
'zztool_token': "申请账号"
}
api_post_url = 'http://v1-http-api.jsdama.com/api.php?mod=php&act=upload'
res_code = requests.post(api_post_url, headers=headers_code, data=data, files=files, verify=False,timeout=10)
print(res_code.json())
url_02 = "https://www.myerong.com/auth.action?callback=jQuery112406286717784912901_1581413388276"
headers = {
"Accept":"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01",
"Accept-Encoding":"gzip, deflate, br",
"Accept-Language":"zh-CN,zh;q=0.9",
"Cache-Control":"no-cache",
"Connection":"keep-alive",
"Content-Length":"62",
"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",
"Cookie":"Hm_lvt_7aa1ece4891bbe95ff97d9fc51c51c42=1581413386; Hm_lpvt_7aa1ece4891bbe95ff97d9fc51c51c42=1581413389;
__session__key__register__code__=PmK8X263rekFTo1Q3Fonwg==",
"Host":"www.myerong.com",
"Origin":"https://www.myerong.com",
"Pragma":"no-cache",
"Referer":"https://www.myerong.com/sites/pages/login/login.html",
"Sec-Fetch-Mode":"cors",
"Sec-Fetch-Site":"same-origin",
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36",
"X-Requested-With":"XMLHttpRequest",
}
data = {
"method": "checkVerrifyCode",
"verrifyCode":res_code.json()['data']['val'],
"subtime": str(t),
}
res =session.post(url_02,headers=headers,data=data,verify=False)
print(res.text)