本帖最后由 yagiza 于 2020-8-13 11:27 编辑
看的头疼,帮你代码写入
[Asm] 纯文本查看 复制代码 import requests
import json
class EasyKFC:
URL = "http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=cname"
# 得到所在城市kfc门店的数量 params:int
@staticmethod
def get_num(city):
"""
:param city:str
:return:int
"""
params = {
'cname': city,
'pageSize': 0
}
html = requests.post(EasyKFC.URL, data=params)
info = json.loads(html.text)
return int(info['Table'][0]['rowcount'])
# 得到所有kfc门店
@staticmethod
def get_all_info(city):
"""
:param city:str
:return:dict
"""
params = {
'cname': city,
'pageSize': EasyKFC.get_num(city)
}
html = requests.post(EasyKFC.URL, data=params)
info = json.loads(html.text)
info['rowcount'] = int(info['Table'][0]['rowcount'])
for i in info['Table1']:
i['addressDetail'] = i['cityName'] + i['addressDetail']
i['storeName'] = i['storeName'] + '餐厅'
info.pop('Table')
return info
# 指定所在城市kfc最大获取数量 返回一个字典,
@staticmethod
def get_info(city, num):
"""
:param city:str
:param num:int
:return:dict
"""
params = {
'cname': city,
'pageSize': num
}
html = requests.post(EasyKFC.URL, data=params)
info = json.loads(html.text)
info['rowcount'] = int(info['Table'][0]['rowcount'])
for i in info['Table1']:
i['addressDetail'] = i['cityName'] + i['addressDetail']
i['storeName'] = i['storeName'] + '餐厅'
info.pop('Table')
return info |