"""
作者:Acha
时间:2021-2-15
功能:查询肯德基地址信息
"""
import requests
# 肯德基URL
url = 'http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=keyword'
# 提示进入操作界面
print(" ========= 欢迎使用 肯德基地址查询 =========", '\n')
# 请求头
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64)"
" AppleWebKit/537.36 (KHTML, like Gecko)"
" Chrome/87.0.4280.141"
" Safari/537.36"}
# 城市,关键字 查询
city = str(input("输入城市 >> "))
keyword = str(input("输入关键字 >> "))
# 查询前 5 页地址
for i in range(5):
# 动态参数
data = {
"cname": city,
"pid": '',
"keyword": keyword,
"pageIndex": str(i),
"pageSize": "10"
}
# 请求体
response = requests.post(url=url, headers=headers, data=data)
# 肯德基地址 列表
list_addr = response.json()['Table1']
# 遍历 输出肯德基地址
for row in list_addr:
print(row['storeName']+'餐厅', row['addressDetail'], row['pro'])