爬取肯德基餐厅查询
程序员文章站
2022-05-02 20:48:03
...
1 需求
爬取肯德基餐厅查询指定地点的餐厅数据,并实现持续化存储。
2 代码实现
import requests
url = "http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx"
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0'}
place = input("Please enter a place: ")
data = {
'op': "keyword",
'cname': '',
'pid': '',
'keyword': place,
'pageSize': '10',
}
response = requests.post(url=url, data=data, headers=headers)
page_text = response.text
fileName = 'KFC.text'
with open(fileName, 'w', encoding='utf-8') as fp:
fp.write(page_text)
print("OVER!")
上一篇: 异地恋分手复合冷淡期怎么度过?
下一篇: 分手后复合的qq说说大全