kfc店铺位置
1 import requests 2 list=[] 3 def ua(place="北京",pageIndex="1"): 4 cookies = { 5 'route-cell': 'ksa', 6 'ASP.NET_SessionId': 'unlvrjaq405kxftmopzeerp2', 7 'Hm_lvt_1039f1218e57655b6677f30913227148': '1649679619', 8 'Hm_lpvt_1039f1218e57655b6677f30913227148': '1649679619', 9 'Hm_lvt_5fd8501a4e4e0eddf0c4596de7bd57ab': '1649679619', 10 'Hm_lpvt_5fd8501a4e4e0eddf0c4596de7bd57ab': '1649679655', 11 'SERVERID': '7b574a5ee35938b607213c6a1c6f2c4a|1649679786|1649679619', 12 } 13 14 headers = { 15 'Connection': 'keep-alive', 16 'Accept': 'application/json, text/javascript, */*; q=0.01', 17 'X-Requested-With': 'XMLHttpRequest', 18 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36', 19 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 20 'Origin': 'http://www.kfc.com.cn', 21 'Referer': 'http://www.kfc.com.cn/kfccda/storelist/index.aspx', 22 'Accept-Language': 'zh-CN,zh;q=0.9', 23 } 24 25 params = { 26 'op': 'keyword', 27 } 28 29 data = { 30 'cname': '', 31 'pid': '', 32 'keyword': place, 33 'pageIndex': pageIndex, 34 'pageSize': '10', 35 } 36 return headers,params,cookies,data 37 38 for i in range(1,11): 39 headers,params,cookies,data=ua("北京",i) 40 response = requests.post('http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx', headers=headers, params=params, 41 cookies=cookies, data=data, verify=False) 42 result=response.json() 43 list.append(result) 44 print("--------") 45 list =str(list) 46 filename = "kfc.html" 47 with open(filename, "w+",encoding='utf-8') as fp: 48 fp.write(list) 49 print("完成")