程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python crawler series KFC home delivery applet kbcts, kbsv algorithm

編輯:Python

Python Crawler series KFC home delivery applet kbcts、kbsv Algorithm

If you have any questions > Click here to communicate with me <

Please scan the QR code below for wechat

The code is for learning and communication only , Do not use for illegal purposes

Go straight to the code

import requests
import json
import time
import random
from RedisUtil import RedisUtil
import hashlib
retry = 3
timeout = 20
kw = "wx_code_"
r = RedisUtil()
userUniqueId = None
token = None
def getCode():
while True:
keys = r.getLikeKeys(kw)
if keys is not None and len(keys) > 0:
key = random.choice(keys)
code = r.get(key)
r.rm(key)
return code
else:
print(" No... Available code, Waiting for production ......")
time.sleep(5)
def postHtml(url, data, headers):
for i in range(retry):
try:
resp = requests.post(url, data=data, headers=headers, timeout=timeout)
return resp.json()
except Exception as e:
print(e)
pass
def getHtml(url, headers):
for i in range(retry):
try:
resp = requests.get(url, headers=headers, timeout=timeout)
return resp.json()
except Exception as e:
pass
def getMd5(s):
m = hashlib.md5()
m.update(s.encode("utf-8"))
return m.hexdigest()
def getHeaders(urlPath, data):
kbcts = getKbcts()
kbsv = getKbsv(urlPath, data, kbcts)
return {

"user-agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36 MicroMessenger/7.0.9.501 NetType/WIFI MiniProgramEnv/Windows WindowsWechat",
"content-type": "application/json",
"kbck": "",
"kbcts": kbcts,
"kbiz": "kfcDelivery",
"kbsv": kbsv,
}
def updateToken():
global token
while True:
url = "https://authlogin.kfc.com.cn/api/wx/lapp/login"
data = {

"code": getCode(),
"md5appid": "a4fde03f5dbf96b1270253c3d03ed30b"
}
headers = getHeaders("/wx/lapp/login", data)
res = postHtml(url, json.dumps(data), headers)
try:
token = res['data']['token']
if token is not None:
return
except Exception as e:
pass
print("/api/wx/lapp/login obtain token Failure !")
time.sleep(5)
def updateUserUniqueId():
global userUniqueId
while True:
url = "https://wechat.4008823823.com.cn/base/v2/initial"
data = {

"body": {
},
"portalType": "kfc_delivery_wechatmini",
"portalSource": "KFC_WEAPP",
"userUniqueId": "",
"token": "",
"ticket": "",
"appVerParams": {

"hotUpdateLabel": "updateLabel"
},
"_channel": "WeApp",
"openId": "",
"channelId": "",
"version": "3001.9.0"
}
headers = getHeaders("/base/v2/initial", data)
res = postHtml(url, json.dumps(data), headers)
try:
userUniqueId = res['userUniqueId']
if userUniqueId is not None:
return
except Exception as e:
pass
print("/base/v2/initial obtain userUniqueId Failure !")
time.sleep(5)
def getNearestStore(longitude, latitude):
url = "https://wechat.4008823823.com.cn/misc/v2/getNearestStore"
data = {

"body": {

"webValidateCustomerAddress": {

"addressId": "1",
"cityCode": "0000",
"longitude": longitude,
"latitude": latitude,
"customerId": "1",
"mainAddress": "1",
"supplementalAddress": " nothing "
}
},
"portalType": "kfc_delivery_wechatmini",
"portalSource": "KFC_WEAPP",
"userUniqueId": userUniqueId,
"token": token,
"ticket": token,
"appVerParams": {

"hotUpdateLabel": "updateLabel"
},
"_channel": "WeApp",
"openId": "",
"channelId": "",
"version": "3001.9.0"
}
headers = getHeaders("/misc/v2/getNearestStore", data)
res = postHtml(url, json.dumps(data), headers)
try:
print(res)
except Exception as e:
pass
def ini():
updateToken()
updateUserUniqueId()
def main():
ini()
longitude = "116.375155"
latitude = "39.914521"
getNearestStore(longitude, latitude)
if __name__ == '__main__':
main()

Attached separately : Get any wechat applet code Method , More technical exchanges > Click here to communicate with me <


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved