requests實戰之肯德基餐廳查詢位置爬取
阿新 • • 發佈:2021-02-08
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...")