import requests
import json
import math
if __name__ == "__main__":
# 指定url
url = 'http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=keyword'
# 进行UA伪装
headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36'
}
index = 1
city = input("enter a city:")
data = {
'cname': '',
'pid': '',
'keyword': city,
'pageIndex': index,
'pageSize': '10',
}
response = requests.post(url=url, data=data, headers=headers)
list_data = response.json()
totalcount = 0
#获取总数据量
for i in list_data['Table']:
totalcount = i['rowcount']
pageindex = math.ceil(totalcount/10)
for i in range(pageindex):
data['pageIndex'] = i+1
response = requests.post(url=url, data=data, headers=headers)
list_data = response.json()
for j in list_data['Table1']:
store = j['storeName']
address = j['addressDetail']
print('store:' + store, 'address:' + address + '\n')
Python爬虫 KFC店铺位置抓取
最新推荐文章于 2025-03-03 19:08:33 发布