2019-04-10 智联招聘网

"""
DATE: 2019/4/10 18:40
AUTHOR: AuWu 王震
DESC: TODO 爬一爬北京、上海的python/数据分析/java/ui/算法,这5个岗位的数量
"""

import requests
import json

def midFunc(node):
    for kw in keyword_ls:
        if node == shanghai:
            print('=' * 60)
            print('节点:上海')
            print('岗位:%s' % kw)
        if node == beijing:
            print('=' * 60)
            print('节点:北京')
            print('岗位:%s' % kw)
        crawl(node, kw)

def crawl(node, kw, start=0, count=0):
    page = start/90+1
    print('正在爬取第%s页'%page)
    base_url = 'https://fe-api.zhaopin.com/c/i/sou'
    parames = {
        'start': start,
        'pageSize': 90,
        'cityId': node,
        'kw': kw,
        'kt': 3
    }
    response = requests.get(base_url, params=parames, headers=headers)
    data = response.text
    # print(data)
    data=json.loads(data)
    if data['data']['numFound']!=0:
        for item in data['data']['results']:
            if kw in item['jobName']:
                jobname = item['jobName']
                company = item['company']['name']
                type = item['company']['type']['name']
                salary = item['salary']
                print(jobname,'\t',company,'\t',type,'\t',salary)
                count+=1
            else:continue
        start+=90
        crawl(node, kw, start, count)
    else:
        print('当前城市查找到%s岗位共计%s个'%(kw, count))


if __name__ == '__main__':
    # 'Referer': 'https://sou.zhaopin.com/?jl=538&sf=0&st=0&kw=python&kt=3',
    headers = {
        'Accept': 'application/json, text/plain, */*',
        'Origin': 'https://sou.zhaopin.com',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36',
    }
    shanghai = 538
    beijing = 530
    node_ls = [shanghai, beijing]
    keyword_ls = ['python','数据分析','java','ui','算法']
    for node in node_ls:
        midFunc(node)

你可能感兴趣的:(2019-04-10 智联招聘网)