import requests
Sh_c = input("请输入要查询的地址:")
url = 'http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=keyword'
headers = {
'Host': 'www.kfc.com.cn',
'Proxy-Connection': 'keep-alive',
'Content-Length': '62',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Origin': 'http://www.kfc.com.cn',
'Referer': 'http://www.kfc.com.cn/kfccda/storelist/index.aspx',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8'
}
data = {
'cname':'',
'pid':'',
'keyword':Sh_c,
'pageIndex':'1',
'pageSize':'10'
}
r = requests.post(url,data=data,headers=headers)
str = eval(r.text)
for str2 in str['Table1']:
k = ("编号:%s \n餐厅名称:%s \n餐厅地址:%s \n详情:%s \n省市:%s,%s"
%(str2['rownum'],str2['storeName'],str2['addressDetail'],str2['pro'],str2['provinceName'],str2['cityName']))
print(k)
结果就是这样的,至于内容怎么写入你自己灵活调整(你原本的URL改成我这个也就可以了)
(为什么求助帖还开付费主题{:10_277:})
页:
[1]