如下是爬取饿了么某一地址附近全部商家的简单实现,
可细化点:
1.发现同一手机号请求验证码3次后被要求图形验证,还没去研究解决方法.简单加了个KeyError跳过.
import requests
session = requests.session()
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36'
}
url_1 = 'https://h5.ele.me/restapi/eus/login/mobile_send_code'
tel = input('请输入手机号码:')
data_1 = {'captcha_hash':'',
'captcha_value':'',
'mobile':tel,
'scf':''}
get_token = session.post(url_1, headers=headers, data=data_1).json()
try:
token = get_token['validate_token']
url_2 = 'https://h5.ele.me/restapi/eus/login/login_by_mobile'
code = input('请输入手机验证码:')
data_2 = {'mobile':tel,
'scf':'ms',
'validate_code':code,