zoukankan      html  css  js  c++  java
  • json数据爬虫。requests实现

    get请求

    import json
    import requests
    
    # url = "https://www.mamalaile.cn/mamalailegw/page/waiterList.jsp"
    url = "https://www.mamalaile.cn/momcome-app/waiter/api_queryUserWaiterInfo.do"
    
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'
    }
    
    response = requests.get(url, headers=headers)
    data_str = response.content.decode()
    data_dict = json.loads(data_str)
    print(type(data_dict))
    print(len(data_dict['data']))
    print(data_dict['data'][0]['name'])
    i = 0
    for item in data_dict['data']:
        i += 1
        print(str(i))
        print('姓名:%s'%item['name'])
        print('年龄:%s'%item['age'])
        print('籍贯:%s'%item['place'])
        print('属相:%s'%item['animals'])
    

      

    post传参

    import json
    import requests
    
    url = "http://www.duoxiwa.com/nlh/io/mon/queryMonList.htm"
    
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'
    }
    data_form={
        'pageSize':'1000',
        'currPage':'1'
    }
    response = requests.post(url, headers=headers,data=data_form)
    data_str = response.content.decode()
    data_dict = json.loads(data_str)
    print(type(data_dict))
    print(len(data_dict['data']))
    # print(data_dict['data'])
    # print(data_dict['data'][0]['name'])
    i = 0
    for item in data_dict['data']:
        i += 1
        print(str(i))
        print('姓名:%s' % item['name'])
        print('年龄:%s' % item['age'])
        print('籍贯:%s' % item['placeDesc'])
        print('属相:%s' % item['animal'])
    

      

  • 相关阅读:
    LeetCode:387字符串中唯一出现一一次的字符
    LeetCode-79. 单词搜索
    LeetCode-75. 颜色分类
    LeetCode-121. 买卖股票的最佳时机
    LeetCode-58. 最后一个单词的长度
    LeetCode-1103. 分糖果 II
    LeetCode:283. 移动零
    LeetCode:38. 外观数列
    LeetCode:70. 爬楼梯
    获取美拍视频的链接--JS分析
  • 原文地址:https://www.cnblogs.com/andy9468/p/8277592.html
Copyright © 2011-2022 走看看