1.注,没有实现获取该市的全部信息
2.完整代码
# 获取肯德基门店地址
import requests
import json
url = "http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=keyword"
headers = {
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36"
}
city = input("enter a city:")
data = {
"cname": "",
"pid": "",
"keyword": city,
"pageIndex": "1",
"pageSize": "10"
}
resp = requests.post(url=url,data=data,headers=headers)
fp = open("kfc.json","w",encoding="utf-8")
json.dump(resp.text,fp=fp,ensure_ascii=False)
fp.close()
print("ok")