历经了几天的煎熬,终于学会带着cookie请求网页了,以模拟登陆饿了么网站并获取地址附近商家名称为例子。这几天一直模拟登录不了,今天才发现是请求中的一个url弄错了。。。。。
import os,base64,requests,json,time
session = requests.session()
url = 'https://h5.ele.me/restapi/eus/v3/captchas'
phone_num = input('请输入手机号')
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36',
}
data = {
'captcha_str': phone_num
}
res=requests.post(url,headers=headers,data=data)
yanzhengma = res.json()
cap_hash = yanzhengma['captcha_hash']
cap_img = yanzhengma['captcha_image']
str_img = cap_img[23:]
img = base64.b64decode(str_img)
fh = open('pic.jpg','wb')