标签:title Python abstract 爬虫 detail date json 数据处理 position
爬虫数据处理:根据关键词寻找合适的职位
背景
最近又到了招聘季,有那么多招聘网站,我们该如何根据关键词找出合适的招聘信息呢?本文根据之前的scrapy爬虫结果,对数据进行过滤,寻找合适的职位信息。
数据:
使用Scrapy爬取的职位名称以及对应的业务详情,分别为abstract.json和detail.json。其中
- abstract.json:包括subject、title、link、author、date等,表示职位类型、职位名称、链接、发布者、发布时间等
- detail.json:包括title、detail,表示职位名称和业务详情。
要求是根据指定的关键字列表从数据中提取最近一周的职位信息。
代码如下:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName :wordfilter.py
# @Time :2022/1/19 17:25
# @Author :PangXZ
import json
import re
import datetime
import numpy as np
KEYWORDS = ['xxxx', 'xx', 'xx', 'xxx', 'xxxx']
def load_detail(document):
file = open(document, 'r', encoding='utf-8')
subject = []
for line in file.readlines():
line = line.rstrip(',\n')
content = json.loads(line)
title = content['title']
detail = content['detail']
for keyword in KEYWORDS:
if keyword in str(detail):
title = re.sub(u"\\[.*?]", "", title).strip()
subject.append(title)
subject = list(set(subject))
return subject
def load_abstract(document):
file = open(document, 'r', encoding='utf-8')
abstract = []
today = datetime.date.today()
for line in file.readlines():
line = line.rstrip(',\n')
content = json.loads(line)
title = content['title']
link = content['link']
date = content['date']
year, month, day = map(int, date.split('-'))
if date is not None:
cursor = datetime.date(year, month, day)
if (today - cursor).days < 7:
abstract.append([title, link, date])
return abstract
def get_right_job(position, abstract):
results = []
source_position = list(np.array(abstract).T[0])
source_link = list(np.array(abstract).T[1])
source_date = list(np.array(abstract).T[2])
target_position = position
right_position = list(set(source_position) & set(target_position))
for position in right_position:
i = source_position.index(position)
results.append([position, source_link[i], source_date[i]])
return results
if __name__ == "__main__":
detail_json = 'detail.json'
Positions = load_detail(document=detail_json)
abstract_json = 'abstract.json'
Abstracts = load_abstract(document=abstract_json)
output = get_right_job(position=Positions, abstract=Abstracts)
for pre in output:
print(pre)
执行结果如下:
标签:title,Python,abstract,爬虫,detail,date,json,数据处理,position 来源: https://blog.csdn.net/ARPOSPF/article/details/122588648
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。