import requests import json if __name__ == '__main__': url = "http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx" site = input("城市") param = {'op': 'keyword','cname':'' ,'pid':'' ,'keyword': site,'pageIndex': '1','pageSize': '10'} header = {"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36 Edg/97.0.1072.69"} response = requests.post(url=url,data=param,headers=header) list_name = response.json() print(list_name) fp = open("./餐厅信息.json","w",encoding="utf-8") json.dump(list_name,fp=fp,ensure_ascii=False) print("over!!!")
只有第一页的结果
全部:
import requests import json if __name__ == '__main__&