肯德基餐厅信息查询网址:http://www.kfc.com.cn/kfccda/storelist/index.aspx
import requests url = 'http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=cname' headers = { 'User-Agent':'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.100 Safari/537.36' } address = input('您想查询哪个城市:') for i in range(1,4):#拿前三页数据 data = { 'cname': address, 'pid':'' , 'pageIndex': str(i), 'pageSize': '10', } response = requests.post(url=url,data=data,headers=headers).json() #print(response) for dic in response['Table1']: _storeName = dic['storeName'] _addressDetail = dic['addressDetail'] print(_storeName+_addressDetail)