#main.py
import requests
import json
import pymongo
from multiprocessing import Pool
import time
import random
url = 'https://www.lagou.com/jobs/positionAjax.json?needAddtionalResult=false'
headers = {
'Accept':'application/json, text/javascript, */*; q=0.01',
'Accept-Encoding':'gzip, deflate',
'Accept-Language':'zh-CN,zh;q=0.8',
'Connection':'keep-alive',
'Content-Length':'65',
'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_%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90%E5%B8%88?px=default&city=%E5%85%A8%E5%9B%BD',
'User-Agent':'Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36',
'X-Anit-Forge-Code':'0',
'X-Anit-Forge-Token':'None',
'X-Requested-With':'XMLHttpRequest'
}
def postonepage(pn):
client = pymongo.MongoClient('localhost', 27017)
Lagou = client['Lagou']
position = Lagou['position']
print(pn)
postdata = {
'first': 'false',
'pn': pn,
'kd': '数据分析师'
}
try:
wbdata = requests.post(url,headers = headers,data = postdata)
jdata = wbdata.json()
# print(jdata)
positionResult = jdata['content']['positionResult']
time.sleep(random.randint(4, 8))
# print(positionResult)
for j in positionResult:
i = j['position']
adata = {
'createTime':i['createTime'],
'positionId': i['positionId'],
'positionName':i['positionName'],
'firstType':i['firstType'],
'secondType':i['secondType'],
'education':i['education'],
'city':i['city'],
'salary':i['salary'],
'jobNature':i['jobNature'],
'workYear':i['workYear'],
'companyId':i['companyId'],
'companyFullName':i['companyFullName'],
'financeStage':i['financeStage'],
'companySize':i['companySize'],
'industryField':i['industryField']
}
position.insert_one(adata)
print('success')
except:
print('one error occurred')
if __name__ == '__main__':
alist = list(range(1,500))
pool = Pool(processes=4)
pool.map(postonepage,alist)
爬虫:拉勾职位
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 主要爬了以下几个字段: 岗位名称 公司名称 要求的工作经验 薪资 工作地点。 感谢罗攀攀和向右奔跑以及朋友wili...
- 上次挖了一个坑,今天终于填上了,还记得之前我们做的拉勾爬虫吗?那时我们实现了一页的爬取,今天让我们再接再厉,实现多...
- 感觉好久没写python了哈哈,最近都在忙工作,所以也是没有学习python。刚好凑巧朋友正在找工作,也是java...
- 知己知彼,方可百战不殆。在学习技术的时候我们往往面临太多选择而不知所措,可能是各个方面都有涉猎,对某个领域没有深入...