使用request爬取拉钩网信息
通过cookies信息爬取
分析header和cookies

通过subtext粘贴处理header和cookies信息

处理后,方便粘贴到代码中

爬取拉钩信息代码
import requests
class LagouSpider(object):
def __init__(self):
self.url ='https://www.lagou.com/jobs/positionAjax.json?needAddtionalResult=false'
self.headers ={
"Accept":"application/json, text/javascript, */*; q=0.01",
"Accept-Encoding":"gzip, deflate, br",
"Accept-Language":"zh-CN,zh;q=0.9",
"Connection":"keep-alive",
"Content-Length":"",
"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_python?city=%E5%85%A8%E5%9B%BD&cl=false&fromSearch=true&labelWords=&suginput=",
"User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36",
"X-Anit-Forge-Code":"",
"X-Anit-Forge-Token":"None",
"X-Requested-With":"XMLHttpRequest"
}
self.offset = 0
self.data = {
"first":'true',
"pn":0, # 页数请求
"kd":'python' # 查询关键字
}
self.pos_li = []
self.total = 0
self.pageNo = 0
self.resultSize = 0
def start_request_total(self):
"""
得到拉钩网页数信息
:return:
"""
response = requests.post(url=self.url, headers=self.headers, data=self.data)
html = response.json()
# 得到拉钩工作信息总数
print(html['content']['positionResult'])
self.total = html['content']['positionResult']['totalCount']
# 得到拉钩工作信息每页展示数
self.resultSize = html['content']['positionResult']['resultSize']
# 从0开始
self.pageNo = int(self.total / self.resultSize) if self.total % self.resultSize > 0 else int(self.total / self.resultSize)-1
print(self.pageNo)
print(len(html['content']['positionResult']['result']))
def start_request(self):
"""
得到拉钩每页工作信息
:return:
"""
response = requests.post(url=self.url, headers=self.headers, data=self.data)
html = response.json()
# 得到拉钩工作信息
print(html['content']['positionResult']['result'])
self.pos_li.append(html['content']['positionResult']['result'])
def main(self):
self.start_request_total()
for i in range(self.pageNo):
self.start_request()
print(len(self.pos_li)) # 得到页数
if __name__ == '__main__':
la = LagouSpider()
la.main()
展示结果

使用request爬取拉钩网信息的更多相关文章
- Python3 Scrapy + Selenium + 阿布云爬取拉钩网学习笔记
1 需求分析 想要一个能爬取拉钩网职位详情页的爬虫,来获取详情页内的公司名称.职位名称.薪资待遇.学历要求.岗位需求等信息.该爬虫能够通过配置搜索职位关键字和搜索城市来爬取不同城市的不同职位详情信息, ...
- selelinum+PhantomJS 爬取拉钩网职位
使用selenium+PhantomJS爬取拉钩网职位信息,保存在csv文件至本地磁盘 拉钩网的职位页面,点击下一页,职位信息加载,但是浏览器的url的不变,说明数据不是发送get请求得到的. 我们不 ...
- 爬取拉钩网上所有的python职位
# 2.爬取拉钩网上的所有python职位. from urllib import request,parse import json,random def user_agent(page): #浏览 ...
- python爬虫(三) 用request爬取拉勾网职位信息
request.Request类 如果想要在请求的时候添加一个请求头(增加请求头的原因是,如果不加请求头,那么在我们爬取得时候,可能会被限制),那么就必须使用request.Request类来实现,比 ...
- Python 爬取拉钩网工作岗位
如果拉钩网html页面做了调整,需要重新调整代码 代码如下 #/usr/bin/env python3 #coding:utf-8 import sys import json import requ ...
- ruby 爬虫爬取拉钩网职位信息,产生词云报告
思路:1.获取拉勾网搜索到职位的页数 2.调用接口获取职位id 3.根据职位id访问页面,匹配出关键字 url访问采用unirest,由于拉钩反爬虫,短时间内频繁访问会被限制访问,所以没有采用多线程, ...
- 【实战】用request爬取拉勾网职位信息
from urllib import request import urllib import ssl import json url = 'https://www.lagou.com/jobs/po ...
- 使用nodejs爬取拉勾苏州和上海的.NET职位信息
最近开始找工作,本人苏州,面了几家都没有结果很是伤心.在拉勾上按照城市苏州关键字.NET来搜索一共才80来个职位,再用薪水一过滤,基本上没几个能投了.再加上最近苏州的房价蹭蹭的长,房贷压力也是非常大, ...
- 爬虫基本库request使用—爬取猫眼电影信息
使用request库和正则表达式爬取猫眼电影信息. 1.爬取目标 猫眼电影TOP100的电影名称,时间,评分,等信息,将结果以文件存储. 2.准备工作 安装request库. 3.代码实现 impor ...
随机推荐
- 《CSAPP》地址翻译
本节所使用的符号: 地址翻译 地址翻译是一个N元素的虚拟地址空间(VAS)中的元素和一个M元素的物理地址空间(PAS)中元素之间的映射. 映射实现: MMU利用页表来实现这种映射.CPU中的一个控制寄 ...
- Django的rest_framework的权限组件和频率组件源码分析
前言: Django的rest_framework一共有三大组件,分别为认证组件:perform_authentication,权限组件:check_permissions,频率组件:check_th ...
- [leetcode]32. Longest Valid Parentheses最长合法括号子串
Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...
- C++ 实现分数的四则运算
对分数求加减乘除,以及化简 #include<iostream> #include<math.h> using namespace std; struct Fraction{ ...
- mybatis pagehelper分页插件使用
使用过mybatis的人都知道,mybatis本身就很小且简单,sql写在xml里,统一管理和优化.缺点当然也有,比如我们使用过程中,要使用到分页,如果用最原始的方式的话,1.查询分页数据,2.获取分 ...
- javascript函数闭包(closure)
一,首先感受下javascript函数的闭包 二,闭包 1,定义:闭包就是能够读取其他函数内部变量的函数,由于在javascript语言中,只有在函数内部的子函数才能够读取局部变量,因此可以把闭包简单 ...
- BZOJ1026或洛谷2657 [SCOI2009]windy数
BZOJ原题链接 洛谷原题链接 简单的数位\(DP\),套模板就好. #include<cstdio> #include<cstring> using namespace st ...
- 【Selenium】【BugList2】geckodriver未安装,报:WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
环境信息:Windows7 64位 + python 3.6.5 + selenium 3.11.0 +pyCharm #coding=utf-8 from selenium import webdr ...
- ABP框架系列之二:(Entity Framework Core-实体核心框架)
Introduction(介绍) Abp.EntityFrameworkCore nuget package is used to integrate to Entity Framework (EF) ...
- boost--时间处理
date_time库的时间功能位于名字空间boost::posix_time,它提供了微妙级别(最高可达纳秒)的时间系统,使用需要包含头文件"boost\date_time\posix_ti ...