欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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...")