requests实战之肯德基餐厅查询位置爬取
程序员文章站
2022-05-02 20:43:30
...
requests实战之肯德基餐厅查询位置爬取
在这里插入代码片import requests
if __name__=="__main__":
url = 'http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=keyword'
headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36'
}
kw = input("输入地名")
data={
'cname':'',
'pid':'',
'keyword':kw,
'pageIndex':'1',
'pageSize':'10',
}
response = requests.post(url=url,headers=headers,data=data)
response = response.text
fileName = kw+'.json'
with open(fileName,'w',encoding='utf-8') as fp:
fp.write(response)
print("over...")
上一篇: 爬取千千音乐的歌词、歌曲到本地
下一篇: 封装函数(二)