博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python实现对某招聘网接口测试获取平台信息
阅读量:5328 次
发布时间:2019-06-14

本文共 3189 字,大约阅读时间需要 10 分钟。

"""通过接口测试的技术获取某招聘网平台的资料""" url = "https://www.lagou.com/jobs/positionAjax.json?needAddtionalResult=false" def getHeaders():     headers = {
"Content-Type": "application/json;charset=UTF-8", "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36", "Cookie": "JSESSIONID=ABAAABAAAIAACBI2438D04CF91400F1FF0A2B38358AFFA5; Hm_lvt_4233e74dff0ae5bd0a3d81c6ccf756e6=1550930753; _ga=GA1.2.193872554.1550930753; _gat=1; user_trace_token=20190223220617-301cdfdc-3774-11e9-af96-525400f775ce; LGSID=20190223220617-301ce139-3774-11e9-af96-525400f775ce; PRE_UTM=; PRE_HOST=cn.bing.com; PRE_SITE=https%3A%2F%2Fcn.bing.com%2F; PRE_LAND=https%3A%2F%2Fwww.lagou.com%2F; LGUID=20190223220617-301ce2a8-3774-11e9-af96-525400f775ce; _gid=GA1.2.1796885419.1550930753; index_location_city=%E5%85%A8%E5%9B%BD; SEARCH_ID=a0ad1593bd14438d8a205a17a17f95c1; Hm_lpvt_4233e74dff0ae5bd0a3d81c6ccf756e6=1550930826; LGRID=20190223220730-5b9c7593-3774-11e9-af96-525400f775ce; TG-TRACK-CODE=search_code", "Referer": "https://www.lagou.com/jobs/list_%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E5%B7%A5%E7%A8%8B%E5%B8%88?labelWords=&fromSearch=true&suginput=" } return headers def lagou(page=2): positions = [] r = requests.post( url=url, headers=getHeaders(), data={"first": False,"pn": page,"kd": "自动化测试工程师"}) text = r.text print(text) for i in range(0,15): city = r.json()#["content"]["positionResult"]["result"][i]["city"] print(city) positionAdvantage = r.json()["content"]["positionResult"]["result"][i]["positionAdvantage"] workYear = r.json()["content"]["positionResult"]["result"][i]["workYear"] companyFullName = r.json()["content"]["positionResult"]["result"][i]["companyFullName"] education = r.json()["content"]["positionResult"]["result"][i]["education"] district = r.json()["content"]["positionResult"]["result"][i]["district"] salary = r.json()["content"]["positionResult"]["result"][i]["salary"] companySize = r.json()["content"]["positionResult"]["result"][i]["companySize"] companyLabelList = r.json()["content"]["positionResult"]["result"][i]["companyLabelList"] positionLables = r.json()["content"]["positionResult"]["result"][i]["positionLables"] position = {
"城市":city, "区域":district, "学历":education, "工作年限":workYear, "薪资":salary, "公司名称":companyFullName, "公司大小":companySize, "公司标签":companyLabelList, "工作标签":positionLables, "公司福利":positionAdvantage } positions.append(position) return positions lagou() def writeCsv(): headers = ["城市", "区域", "学历", "工作年限", "薪资", "公司名称", "公司大小", "公司标签", "工作标签","公司福利"] for item in range(1,31): positions = lagou(page=item) with open("lagou.cvs","a") as f: writer = csv.DictWriter(f,headers) writer.writeheader() writer.writerows(positions) writeCsv()

转载于:https://www.cnblogs.com/Teachertao/p/10426440.html

你可能感兴趣的文章
洛谷P1005 矩阵取数游戏
查看>>
Django ORM操作
查看>>
2012年最佳30款免费 WordPress 主题
查看>>
在Silverlight中使用HierarchicalDataTemplate为TreeView实现递归树状结构
查看>>
HDU-1150 Machine Schedule 二分图匹配
查看>>
单例模式的5种写法
查看>>
安卓问题报告小记(四):Some projects cannot be imported because they already exist in the workspace...
查看>>
显示地图
查看>>
无线通信基础(一):无线网络演进
查看>>
如何在工作中快速成长?阿里资深架构师给工程师的10个简单技巧
查看>>
2017.6.4 入门组 NO.4——猜数
查看>>
Eclipse 下载安装
查看>>
WebSocket 时时双向数据,前后端(聊天室)
查看>>
关于cocoa 运行时runtime
查看>>
关于python中带下划线的变量和函数 的意义
查看>>
asp.net 写入excel时,不能更新。数据库或对象为只读。
查看>>
题1简化版
查看>>
linux清空日志文件内容 (转)
查看>>
jsp中对jstl一些标签的引用方式
查看>>
100. Same Tree
查看>>