爬虫学习,肯德基餐厅信息查询

import requests

#url = 'http://www.kfc.com.cn/kfccda/storelist/index.aspx'

url = 'http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=keyword'
for page in range(1,9):
    data = {
        'cname': '',
        'pid': '',
        'keyword': '北京',
        'pageIndex': str(page),
        'pageSize': '10',
    }
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36',
        'Referer': 'http://www.kfc.com.cn/kfccda/storelist/index.aspx',
        'Host': 'www.kfc.com.cn'

    }
    # data参数是post方法中处理参数动态化的参数
    response = requests.post(url=url, headers=headers, data=data)
    page_text = response.json()
    for dic in page_text['Table1']:
        title = dic['storeName']
        addr = dic['addressDetail']
        print(title, addr)


你可能感兴趣的:(笔记)