python3 爬取API数据

爬取高考志愿填报系统(https://gkcx.eol.cn/)的所有学校

(一)、第一种方法

1.分析请求

python3 爬取API数据_第1张图片

2.构造url

 base_url='https://gkcx.eol.cn/gkcx/api?'
    data={
        "uri": "gksjk/api/school/hotlists",
        "province_id": "",
        "type": "",
        "size": 20,
        "page": page,
        "f211": "",
        "f985": "",
        "dual_class": "",
        "is_dual_class": "",
        "admissions": "",
        "central": "",
        "department": "",
        "school_type": "",
        "keyword": "",
        "request_type": 1,
        "sort": "view_total"
    }
    url=base_url+urlencode(data)

结果:

https://gkcx.eol.cn/gkcx/api?uri=gksjk%2Fapi%2Fschool%2Fhotlists&province_id=&type=&size=20&page=1&f211=&f985=&dual_class=&is_dual_class=&admissions=¢ral=&department=&school_type=&keyword=&request_type=1&sort=view_total

打开这个url:

python3 爬取API数据_第2张图片

 解析json:

python3 爬取API数据_第3张图片

3.提取数据:

items=json.get('data').get('item')
    item_list=[]
    for item in items:
        a_dict={}
        a_dict['name']=item.get('name')
        a_dict['type']=item.get('dual_class_name')
        a_dict['origin']=item.get('province_name')
        item_list.append(a_dict)

 结果:

[{'name': '上海理工大学', 'type': '', 'origin': '上海'}, {'name': '上海对外经贸大学', 'type': '', 'origin': '上海'}, {'name': '重庆邮电大学', 'type': '', 'origin': '重庆'}, {'name': '重庆邮电大学移通学院', 'type': '', 'origin': '重庆'}, {'name': '重庆师范大学涉外商贸学院', 'type': '', 'origin': '重庆'}, {'name': '重庆工商大学融智学院', 'type': '', 'origin': '重庆'}, {'name': '黑龙江东方学院', 'type': '', 'origin': '黑龙江'}, {'name': '重庆电子工程职业学院', 'type': '', 'origin': '重庆'}, {'name': '黑龙江外国语学院', 'type': '', 'origin': '黑龙江'}, {'name': '广州工商学院', 'type': '', 'origin': '广东'}, {'name': '河北环境工程学院', 'type': '', 'origin': '河北'}, {'name': '重庆交通职业学院', 'type': '', 'origin': '重庆'}, {'name': '河北旅游职业学院', 'type': '', 'origin': '河北'}, {'name': '承德护理职业学院', 'type': '', 'origin': '河北'}, {'name': '河南师范大学新联学院', 'type': '', 'origin': '河南'}, {'name': '厦门大学', 'type': '双一流', 'origin': '福建'}, {'name': '武汉大学', 'type': '双一流', 'origin': '湖北'}, {'name': '四川大学', 'type': '双一流', 'origin': '四川'}, {'name': '北京大学', 'type': '双一流', 'origin': '北京'}, {'name': '中山大学', 'type': '双一流', 'origin': '广东'}]

4.源码

(二)、第二种方法:

源码联系博主

 

你可能感兴趣的:(spider,teach)