立即学习:https://edu.csdn.net/course/play/24454/306763?utm_source=blogtoedu
import requests import json if __name__ == '__main__': headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36' } url = 'http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=keyword' for num in range(1, 9): #搜索出来的内容页码 北京8页 通过for语句遍历8页的内容 num=str(num) data={ 'cname':'', 'pid':'', 'keyword':'北京', 'pageIndex':num, 'pageSize': '10' } response=requests.post(url=url,data=data,headers=headers) page_text=response.text print(num,page_text) with open('./kendeji.json','w',encoding='utf-8') as fp: fp=json.dump(page_text,fp,ensure_ascii=False) print('Over!!!')