点击最下方的餐厅查询
随便查询一个城市,下方红色方框圈起来的就是Ajax
门店信息:
import urllib.request
import urllib.parse
post_url='http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=cname'
city=input('请输入要查询的城市:')
page=input('请输入要查询第几页:')
size=input('请输入每页要查询多少条信息:')
form_data={
'cname': city,
'pid':' ',
'pageIndex': page,
'pageSize':size,
}
# 伪装头部
headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36',
}
# 转换数据
form_data=urllib.parse.urlencode(form_data).encode()
# 构建请求
request=urllib.request.Request(url=post_url,headers=headers)
# 发送请求
response=urllib.request.urlopen(request,form_data)
print(response.read().decode())
{"Table":[{"rowcount":431}],"Table1":[{"rownum":6,"storeName":"航天桥","addressDetail":"阜成路51-2","pro":"24小时,店内参观","provinceName":"北京市","cityName":"北京市"},{"rownum":7,"storeName":"展览路(德宝)","addressDetail":"西外大街德宝新园14号","pro":"Wi-Fi,店内参观,礼品卡","provinceName":"北京市","cityName":"北京市"},{"rownum":8,"storeName":"劲松","addressDetail":"劲松4区401楼","pro":"24小时,Wi-Fi,店内参观,礼品卡,生日餐会","provinceName":"北京市","cityName":"北京市"},{"rownum":9,"storeName":"西罗园","addressDetail":"西罗园4区南二段","pro":"Wi-Fi,店内参观,礼品卡,生日餐会","provinceName":"北京市","cityName":"北京市"},{"rownum":10,"storeName":"蓝桥","addressDetail":"蓝桥餐厅工体北路11-1号","pro":"24小时,Wi-Fi,点唱机,礼品卡","provinceName":"北京市","cityName":"北京市"}]}