urllib_POST请求KFC官网

本文最后更新于 5 个月前

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

#https://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=cname
#cname: 青岛
#pid:
#pageIndex: 3
#pageSize: 10

import urllib_handler的基本使用.request
import urllib_handler的基本使用.parse
url = 'http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=cname'
def get_post(num):
data = {
'cname': '青岛',
'pageIndex': str(num),
'pageSize': '10'
}
headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
}
data = urllib.parse.urlencode(data).encode('utf-8')
req = urllib.request.Request(url=url, data=data, headers=headers)
response = urllib.request.urlopen(req)
content = response.read().decode('utf-8')
return content
for i in range(1,6):
print(get_post(i))
# with open("qd_KFC_"+str(i)+".json",'a',encoding='utf-8') as f:
# f.write(get_post(i))




PYTHON

urllib_POST请求KFC官网
https://ianwusb.blog/2024/07/26/urllib_POST请求KFC官网/
作者
Ianwusb
发布于
2024年7月26日
许可协议