爬虫,第五次实战之(肯德基地址)

import requests
import json
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36'}
url = 'http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=keyword'
kd = input('输入地址:')
data = {'cname':'',
        'pid':'',
        'keyword':kd,
        'pageIndex':'1',
        'pageSize':'10'}
response = requests.post(url=url,data=data,headers=headers)
obj = response.json()
name = kd+'.json'
fp = open(name,'w',encoding='UTF-8')
json.dump(obj=obj,fp=fp,ensure_ascii=False)
print('END!!')

 

转载于:https://www.cnblogs.com/sucanji/p/10836245.html

你可能感兴趣的:(爬虫,第五次实战之(肯德基地址))