import requests
import json
header = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'
}
post_url = 'http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=keyword'
kw = input('Enter city:')
data = {
'cname': '',
'pid': '',
'keyword': kw,
'pageIndex': '1',
'pageSize': '10'
}
response = requests.post(url=post_url, data=data, headers=header)
page_text = response.json()
fileName = kw + '.json'
fp = open(fileName, 'w', encoding='utf-8')
json.dump(page_text, fp=fp, ensure_ascii=False)
print('爬取结束!!!')