腾讯招聘网数据爬取存入mongodb
#!/user/bin/env python3
# -*- coding: utf-8 -*-
import requests
from lxml import etree
from math import ceil
from mongodb_config import mongo_info
header = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 '
'Safari/537.36'}
# 获取岗位页数
def getJobPage(url):
res = requests.get(url, headers=header)
html = etree.HTML(res.text)
total = html.xpath('//div[@class="left"]/span/text()')[0]
job_page = ceil(int(total) / 10)
return job_page
# 获取详情页职位描述
def getJobOrder(url):
# url = 'https://hr.tencent.com/position_detail.php?id=49256&keywords=&tid=0&lid=0'
res = requests.get(url, headers=header)
html = etree.HTML(res.text)
detail_info = html.xpath('//table[@class="tablelist textl"]')
for item in detail_info:
# 工作职责
job_request = item.xpath('tr[3]//ul[@class="squareli"]/li/text()')
# 工作要求
job_order = item.xpath('tr[4]/td/ul[@class="squareli"]/li/text()')
# print(job_request)
# print(job_order)
list_data = [job_request, job_order]
return list_data
# 获取列表页岗位信息
def getJobInfo(url):
res = requests.get(url, headers=header)
html = etree.HTML(res.text)
job_list = html.xpath('//tr[@class="even" or @class="odd"]')
list_data = []
href = 'https://hr.tencent.com/'
for list_job in job_list:
dict_item = {}
# print(etree.tostring(list_job, encoding='utf-8').decode('utf-8'))
detail_url = href + list_job.xpath('.//a/@href')[0]
job_name = list_job.xpath('.//td[1]/a/text()')[0]
job_type = list_job.xpath('.//td[2]/text()')[0]
job_people = list_job.xpath('.//td[3]/text()')[0]
job_addre = list_job.xpath('.//td[4]/text()')[0]
job_time = list_job.xpath('.//td[5]/text()')[0]
# 工作职责
job_request = getJobOrder(detail_url)[0]
# 工作要求
job_order = getJobOrder(detail_url)[1]
dict_item['detail_url'] = detail_url
dict_item['job_name'] = job_name
dict_item['job_type'] = job_type
dict_item['job_people'] = job_people
dict_item['job_addre'] = job_addre
dict_item['job_time'] = job_time
dict_item['job_request'] = job_request
dict_item['job_order'] = job_order
list_data.append(dict_item)
mongo_info.update_tencent(list_data)
print(list_data)
if __name__ == '__main__':
mainurl = 'https://hr.tencent.com/position.php?&start=0#a'
jobPage = getJobPage(mainurl)
for page in range(jobPage):
pageUrl = 'https://hr.tencent.com/position.php?&start=' + str(page * 10) + '#a'
print("第" + str(page + 1) + "页")
getJobInfo(pageUrl)
# getJobOrder()
#!/user/bin/env python3
# -*- coding: utf-8 -*-
from pymongo import MongoClient
class Connect_mongo(object):
def __init__(self):
# 无密码认证使用该代码
# self.client = MongoClient(host='127.0.0.1', port=27017)
# self.client = MongoClient(host='192.168.1.191', port=27017)
# 有密码认证使用该代码
self.client = MongoClient(host='127.0.0.1', port=27017)
# self.client = MongoClient(host='192.168.1.193', port=27017)
# 数据库名loan
self.database = self.client.loan
self.tencent_database = self.client.tencent
# 认证用户密码
self.dbinfo = self.database.authenticate('xxx', 'xxxx')
self.tencent_dbinfo = self.tencent_database.authenticate('xxx', 'xxx')
# 无密码认证
# 查询全部产品名
def find_all_name(self):
_database = self.client.loan
_collection = _database.loan_datase_sums
loan_name = _collection.find({}, {'_id': 0, 'loan_name': 1})
return loan_name
# 去重查询
def find_distinct_name(self):
_database = self.client.loan
_collection = _database.loan_datase_sums
loan_name = _collection.distinct('loan_name')
return loan_name
def update_data(self, document):
_client = self.client
_database = self.database
self.dbinfo
_collection = _database.loan_datase_sums
for res in document:
result = _collection.update_many({'loan_name': res['loan_name']}, {'$set': res}, upsert=True)
return result
def update_rong360(self, document):
_client = self.client
_database = self.database
self.dbinfo
_collection = _database.rong360
for res in document:
result = _collection.update_many({'loan_name': res['loan_name']}, {'$set': res}, upsert=True)
return result
def update_tencent(self, document):
_client = self.client
_database = self.tencent_database
self.tencent_dbinfo
_collection = _database.advertise_datase
for res in document:
result = _collection.update_many({'job_name': res['job_name']}, {'$set': res}, upsert=True)
return result
mongo_info = Connect_mongo()
腾讯招聘网数据爬取存入mongodb的更多相关文章
- Scrapy实现腾讯招聘网信息爬取【Python】
一.腾讯招聘网 二.代码实现 1.spider爬虫 # -*- coding: utf-8 -*- import scrapy from Tencent.items import TencentIte ...
- Python爬虫入门教程 3-100 美空网数据爬取
美空网数据----简介 从今天开始,我们尝试用2篇博客的内容量,搞定一个网站叫做"美空网"网址为:http://www.moko.cc/, 这个网站我分析了一下,我们要爬取的图片在 ...
- 人人贷网的数据爬取(利用python包selenium)
记得之前应同学之情,帮忙爬取人人贷网的借贷人信息,综合网上各种相关资料,改善一下别人代码,并能实现数据代码爬取,具体请看我之前的博客:http://www.cnblogs.com/Yiutto/p/5 ...
- 爬虫1.5-ajax数据爬取
目录 爬虫-ajax数据爬取 1. ajax数据 2. selenium+chromedriver知识准备 3. selenium+chromedriver实战拉勾网爬虫代码 爬虫-ajax数据爬取 ...
- 基于 PHP 的数据爬取(QueryList)
基于PHP的数据爬取 官方网站站点 简单. 灵活.强大的PHP采集工具,让采集更简单一点. 简介: QueryList使用jQuery选择器来做采集,让你告别复杂的正则表达式:QueryList具有j ...
- 移动端数据爬取和Scrapy框架
移动端数据爬取 注:抓包工具:青花瓷 1.配置fiddler 2.移动端安装fiddler证书 3.配置手机的网络 - 给手机设置一个代理IP:port a. Fiddler设置 打开Fiddler软 ...
- 小爬爬5:重点回顾&&移动端数据爬取1
1. ()什么是selenium - 基于浏览器自动化的一个模块 ()在爬虫中为什么使用selenium及其和爬虫之间的关联 - 可以便捷的获取动态加载的数据 - 实现模拟登陆 ()列举常见的sele ...
- Web Scraper——轻量数据爬取利器
日常学习工作中,我们多多少少都会遇到一些数据爬取的需求,比如说写论文时要收集相关课题下的论文列表,运营活动时收集用户评价,竞品分析时收集友商数据. 当我们着手准备收集数据时,面对低效的复制黏贴工作,一 ...
- python实现人人网用户数据爬取及简单分析
这是之前做的一个小项目.这几天刚好整理了一些相关资料,顺便就在这里做一个梳理啦~ 简单来说这个项目实现了,登录人人网并爬取用户数据.并对用户数据进行分析挖掘,终于效果例如以下:1.存储人人网用户数据( ...
随机推荐
- Consul在linux系统, 群集实战
Consul作为微服务的服务注册与发现组件,是非常重要的一部分 目前想用Consul作为配置管理的统一管理 准备两台机器 11.11.11.1011.11.11.20 下载consul linux版 ...
- #单元测试#以karma+mocha+chai 为测试框架的Vue webpack项目(二)
学习对vue组件进行单元测试,先参照官网编写组件和测试脚本. 1.简单的组件 组件无依赖,无props 对于无需导入任何依赖,也没有props的,直接编写测试案例即可. /src/testSrc/si ...
- vue2.x 随记
1. 外部js调用vue的方法等 将vue实例中的this传入外部js文件(比如作为某方法的参数),即可访问传入实例的所有内容.调用该实例中子组件的方法,用$refs. 2. 路由参数 传递:vm.$ ...
- python入门5 运算符
python运算符: 1 算术运算符 加减乘除 取余 求商 求幂等 2 比较运算符== != > >= < <= 3 逻辑运算符 and not or 4 赋值运 ...
- IOS ASI 请求服务器 总结
一.发送请求的2个对象 1.发送GET请求:ASIHttpRequest 2.发送POST请求:ASIFormDataRequest* 设置参数// 同一个key只对应1个参数值,适用于普通“单值参数 ...
- POJ-3267 The Cow Lexicon---删除字符匹配单词
题目链接: https://cn.vjudge.net/problem/POJ-3267 题目大意: 题意就是给出一个主串,和一本字典,问最少在主串删除多少字母,可以使其匹配到字典的单词序列. PS: ...
- Android(java)学习笔记14:Java线程池
1. 线程池: 1)程序启动一个新线程成本是比较高的,因为它涉及到要与操作系统进行交互.而使用线程池可以很好的提高性能,尤其是当程序中要创建大量生存期很短的线程时,更应该考虑使用线程池. 2)线程池里 ...
- Codeforces Round #515 (Div. 3) B. Heaters【 贪心 区间合并细节 】
任意门:http://codeforces.com/contest/1066/problem/B B. Heaters time limit per test 1 second memory limi ...
- msfconsole_无法启动问题
service postgresql start # 启动数据库服务 msfdb init # 初始化数据库 msfconsole # 启动metasploit
- doppia代码结构
代码地址:https://bitbucket.org/rodrigob/doppia/src stereo_matching下的几个目录相当于这几篇论文中求stixel的几个步骤 cost_volum ...