Python爬取智联招聘数据分析师岗位相关信息的方法

yipeiwu_com5年前Python爬虫

进入智联招聘官网,在搜索界面输入‘数据分析师',界面跳转,按F12查看网页源码,点击network

 选中XHR,然后刷新网页

可以看到一些Ajax请求, 找到画红线的XHR文件,点击可以看到网页的一些信息

在Header中有Request URL,我们需要通过找寻Request URL的特点来构造这个请求网址,

点击Preview,可以看到我们所需要的信息就存在result中,这信息基本是json格式,有些是列表;

下面我们通过Python爬虫来爬取上面的信息;

代码如下:

import requests
from urllib.parse import urlencode
import json
#from requests import codes
#import os
#from hashlib import md5
#from multiprocessing.pool import Pool
#import re
 
 
def get_page(offset):
  params = {
    'start': offset,
    'pageSize': '90',
    'cityId': '530',
    'salary': '0,0',
    'workExperience': '-1',
    'education': '-1',
    'companyType': '-1',
    'employmentType': '-1',
    'jobWelfareTag': '-1',
    'kw': '数据分析师',
    'kt': '3',
    '_v': '0.77091902',
    'x-zp-page-request-id': '8ff0aa73bf834b408f46324e44d89b84-1562722989022-210101',
    'x-zp-client-id': '2dc4c9a4-e80d-4488-84a3-03426dd69a1e'
    
    
  }
  base_url = 'https://fe-api.zhaopin.com/c/i/sou?'
  url = base_url + urlencode(params)
  try:
    resp = requests.get(url)
    print(url)
    if 200 == resp.status_code:
      print(resp.json())
      return resp.json()
  except requests.ConnectionError:
    return None
 
 
def get_information(json_page):
  if json_page.get('data'):
    results = json_page.get('data').get('results')    
    for result in results:
       yield {
         'city': result.get('city').get('display'),
          'company': result.get('company').get('name'),
          #'welfare':result.get('welfare'),
          'workingExp':result.get('workingExp').get('name'),
          'salary':result.get('salary'),
          'eduLevel':result.get('eduLevel').get('name')
        }
print('succ')
 
def write_to_file(content):
   with open('result.txt','a',encoding='utf-8') as f:
      print(type(json.dumps(content)))
      f.write(json.dumps(content,ensure_ascii=False)+'\n')
   
   
def main(offset):
  json_page=get_page(offset)  
  for content in get_information(json_page):
    write_to_file(content)
  
if __name__=='__main__':
   for i in range(10):
      main(offset=90*i)

爬取结果如下:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

关于反爬虫的一些简单总结

关于反爬虫的一些简单总结

爬虫与反爬虫,这相爱相杀的一对,简直可以写出一部壮观的斗争史。而在大数据时代,数据就是金钱,很多企业都为自己的网站运用了反爬虫机制,防止网页上的数据被爬虫爬走。然而,如果反爬机制过于严格...

Python使用爬虫抓取美女图片并保存到本地的方法【测试可用】

Python使用爬虫抓取美女图片并保存到本地的方法【测试可用】

本文实例讲述了Python使用爬虫抓取美女图片并保存到本地的方法。分享给大家供大家参考,具体如下: 图片资源来自于www.qiubaichengren.com 代码基于Python 3....

Python3爬虫之自动查询天气并实现语音播报

Python3爬虫之自动查询天气并实现语音播报

一、写在前面 之前写过一篇用Python发送天气预报邮件的博客,但是因为要手动输入城市名称,还要打开邮箱才能知道天气情况,这也太麻烦了。于是乎,有了这一篇博客,这次我要做的就是用Pyth...

Python学习笔记之抓取某只基金历史净值数据实战案例

Python学习笔记之抓取某只基金历史净值数据实战案例

本文实例讲述了Python抓取某只基金历史净值数据。分享给大家供大家参考,具体如下: http://fund.eastmoney.com/f10/jjjz_519961.html 1、...

Pyspider中给爬虫伪造随机请求头的实例

Pyspider 中采用了 tornado 库来做 http 请求,在请求过程中可以添加各种参数,例如请求链接超时时间,请求传输数据超时时间,请求头等等,但是根据pyspider的原始框...