爬取地区肯德基餐厅位置

2020-11-04  本文已影响0人  Rain师兄

import requests

import json

if __name__ =='__main__':

                url ='http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=keyword'

                headers = {'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Safari/605.1.15'}

                word =input('enter: ')

                for iin range(7):

                        data = {

                        'cname':'',

                        'pid':'',

                        'keyword':word,

                        'pageIndex':i+1,

                        'pageSize':'10'

            }

                        resp = requests.post(url=url,data=data,headers=headers)

                        kfc = resp.text

                        filename = word +'.json'

                        fp =open(filename,'a',encoding='utf-8')

                        json.dump(kfc,fp=fp,ensure_ascii=False)

                        print('over!!!!')

得到

把内容复制到txt文件里面

上一篇 下一篇

猜你喜欢

热点阅读