Python爬取智联招聘数据分析师岗位相关信息的方法
2019-08-13 11:10
1116 查看
进入智联招聘官网,在搜索界面输入‘数据分析师',界面跳转,按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项目实战:用多进程(multiprocessing)+多线程(threading)的方式并发爬取智联招聘爬虫岗位信息并存入MongoDB
- python爬虫实战-爬取岗位招聘信息并保存至本地(方法、bs4)
- python爬虫实战-爬取岗位招聘信息并保存至本地(方法、jsonpath)
- python3字典相关方法
- python 中 打印及格式化字符串的相关方法
- 用Python获取腾迅财经HTTP信息股票数据的方法
- phpcms v9后台添加文章时选择相关文章可调用其它模型信息的方法
- 用Python从智联招聘自动爬取招聘信息
- windows安装redis MySQL-python相关方法
- 在Python常用模块I如何打开相关文件的方法
- Ubuntu16.04下安装搭配Python3.6相关配置软件方法
- Python实现批量读取word中表格信息的方法
- python实现上传样本到virustotal并查询扫描信息的方法
- 各类Java heap space 解决方法,并通过java代码获取JVM的相关信息,所在操作系统的信息(包含eclipse&myeclipse的调试的内存设置)
- Build相关属性和调用系统信息的方法
- python模拟翻页+提取相关信息
- python爬虫使用selenium爬取动态网页信息——以智联招聘网站为例
- Java获取系统信息(cpu,内存,硬盘,进程等)的相关方法
- php获取服务器操作系统相关信息的方法
- Python爬虫爬取智联招聘职位信息