python requests用接口爬拉钩网职位信息
来源:互联网 发布:linux 大文件中查找 编辑:程序博客网 时间:2024/05/17 17:15
# -*- coding:utf-8 -*-# 参考:http://docs.python-requests.org/zh_CN/latest/user/quickstart.html# 请求返回的是dict套接的形式,可用iteritems或者.json()转化成列表读取__author__ = 'binsen'import sys,requests,jsonreload(sys)sys.setdefaultencoding('utf-8')kong = []for page in range(1, 15): url = 'https://www.lagou.com/jobs/positionAjax.json' # proxies = {"http":"http://125.105.17.229:808"} headers = {'Accept':'application/json, text/javascript, */*; q=0.01', 'Accept-Encoding':'gzip, deflate, br', 'Accept-Language':'zh-CN,zh;q=0.8', 'Connection':'keep-alive', 'Content-Length':'55', 'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8', 'Cookie': '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~', 'Host':'www.lagou.com', 'Origin':'https://www.lagou.com', 'Referer':'https://www.lagou.com/jobs/list_%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95?city=%E4%B8%8A%E6%B5%B7\&cl=false&fromSearch=true&labelWords=&suginput=', 'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.28\40.99 Safari/537.36', 'X-Anit-Forge-Code':'0', 'X-Anit-Forge-Token':'None', 'X-Requested-With':'XMLHttpRequest' } payload = {'px':'default','city':'杭州','needAddtionalResult':'false','first':'true', 'pn':page, 'kd':'python'} response = requests.post(url,data = payload,headers = headers) # 开启了鉴权的接口,加auth和HTTPBasicAuth wenben = response.text # 打印出文本 # response = requests.post(url,data = payload,proxies = proxies) # print type(response.content),type(wenben) # content取的是二进制str数据,可以取到图片,文件等数据,text取unicode的文本 # print response.status_code response_json = response.json() # 从接口返回值中取出json字符串转成python字符串。此处也可用json.loads(wenben)反序列化转成python对象 # print response_json # 多条公司的招聘数据,后续迭代出来 res = response_json['content']['positionResult']['result'] # print type(res) list print '正在爬取拉钩网第 %s 页の %s 职位的信息...' % (str(page), payload['kd']) for x in res: xinxi = "岗位:%s,公司名:%s,规模:%s,业务:%s,工作年限:%s,待遇:%s" % (x['positionName'],x['companyFullName'],\x['companySize'],x['industryField'],x['workYear'],x['salary']) kong.append(xinxi)with open('C:/Users/bin.sun/Desktop/lagou.txt', 'a') as file: for index,i in enumerate(kong, start=1): index1 = '%03d' % index shuju = index1 + ' ' + i + '\n' file.write(shuju)
阅读全文
0 0
- python requests用接口爬拉钩网职位信息
- 用Python爬取拉钩网招聘职位信息
- 第一个爬虫(拉钩网的所有职位信息)
- 使用scrapy+IP代理+多线程爬虫对拉钩网在杭州互联网职位信息的抓取
- Python 简单爬虫的样例(获取拉钩网Python的职位)
- python数据爬虫---拉钩网
- 爬虫:用Python爬取招聘职位信息&职位需求分析
- python urllib2用url爬前程无忧职位信息
- Python爬取网站职位信息
- 拉钩网
- python scrapy爬虫 CrawlSpider 拉钩招聘网302重定向问题解决方案 , 修改setting信息,添加cookie请求
- python+requests+excel 接口测试
- python+requests实现接口测试
- Python + Requests 实现接口自动化
- python+requests实现接口测试
- Python selenium 拉钩爬虫
- 利用Python的requests模块爬取当当网的书籍信息(待续)
- python:使用requests和bs4爬去豆瓣图书信息
- 正定矩阵
- Android APP秒开
- [日推荐]『小谈吧』一种新的开会方式
- 627. Swap Salary
- 六、JSP——Cookie
- python requests用接口爬拉钩网职位信息
- Redundant Paths POJ
- Leetcode#190. Reverse Bits (反向位&位运算)
- Window.open()方法参数详解
- 如何在WPF或者C#中打开外部资源:System.Diagnostics.Process.Start()
- Count and Say
- 二分
- 做题
- Android Multimedia框架总结(八)Stagefright框架之AwesomePlayer及数据解析器