• 爬虫代码


    import requests
    import json
    url = 'http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=keyword'
    keyword = input('请输入要查询的地名:')
    data = { 'cname':'', 'pid': '','keyword': keyword , 'pageIndex': '1', 'pageSize': '100'}
    header = { 'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132Safari/537.36'}
    response = requests.post(url=url, data=data, headers=header)
    content_json = response.json()
    content_json = json.dumps(content_json,ensure_ascii=False)
    result = json.loads(content_json)
    print(result)
               
    storelist = result['Table1']
    for store in storelist:
     print(store['storeName'],store['addressDetail'])

    爬取肯德基餐厅地址的代码
    功能:通过输入地区名称,显示当地的肯德基餐厅地址


    import requests
    import json
    
    url='https://movie.douban.com/j/chart/top_list?'
    params = {'type': '11','interval_id':'100:90','action':'','start':'0','limit':'200'}
    header = {'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36'}
    response = requests.get(url=url,params=params,headers=header)
    content = response.json()
    for item in content:
     print(item['rank'],item['title'])

    爬取豆瓣前200的影片信息代码

    功能:通过修改params的信息(type:种类;start:起始;limit:末尾)

    import requests
    import json
    url=‘https://movie.douban.com/j/chart/top_list?type=11&interval_id=100%3A90&acti
    on=&start=0&limit=20'
    params = {'type': '11','interval_id':'100:90','action':
    '','start':'0','limit':'200'}
    header = {'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0)
    AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36'}
    response = requests.get(url=url,headers=header)
    content = response.json()
    for item in content:
     print(item['rank'],item['title'])

  • 相关阅读:
    FormsAuthentication.HashPasswordForStoringInConfigFile方法再.net core中的替代代码
    git 删除分支和回退到以前某个提交版本
    .net core 2.1控制台使用Quartz.net实现定时任务执行
    CodeForces
    CodeForces
    CCF 201709-2 公共钥匙盒
    POJ
    CodeForces
    (转)Django vs Flask vs Pyramid: Choosing a Python Web Framework
    (转)Seven Ways of Centering With CSS
  • 原文地址:https://www.cnblogs.com/YanZhuDL/p/14515869.html
Copyright © 2020-2023  润新知