forked from zhanghe06/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path51job.py
More file actions
166 lines (136 loc) · 5.21 KB
/
51job.py
File metadata and controls
166 lines (136 loc) · 5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# encoding: utf-8
__author__ = 'zhanghe'
import requests
from lxml import etree
header = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36',
}
s = requests.session()
tree = None
url_root = 'http://search.51job.com/jobsearch/search_result.php'
payload = {
'fromJs': '1',
'jobarea': '010000', # 城市地区
'funtype': '0000', # 职能类别(0000:全部)
'industrytype': '00', # 行业
'issuedate': '8', # 发布时间(1:近1天,2:近2天,3:近3天,4:近1周,5:近2周,6:近1月,7:近6周,8:近两月,9:所有)
'providesalary': '99', # 工资
'keywordtype': '1', # 关键词类型(0:公司名,1:职位名,2:全文)
'lang': 'c', # 语言
'stype': '2', #
'workyear': '99', # 工作经验(99:所有)
'cotype': '99', # 公司性质(99:所有)
'degreefrom': '99', # 最低学历(99:所有)
'jobterm': '01', # 工作类型(0:全职,1:兼职,01:全部)
'companysize': '99', # 公司规模(99:所有)
'fromType': '1' #
}
# 筛选条件:职能类别/行业类别/工作地点 至少要有一个
position_dict = {
# 公司信息
'company_name': '',
'company_url': '',
'company_industry': '', # 公司行业
'company_property': '', # 公司性质
'company_size': '', # 公司规模
# 职位信息
'position_create_time': '', # 发布日期
'position_area': '', # 工作地点(地区)
'position_recruit_num': '', # 招聘人数
'position_work_years': '', # 工作年限
'position_language_limit': '', # 语言要求
'position_degree_limit': '', # 学 历
'position_salary_range': '', # 薪资范围
'position_benefit': '', # 薪酬福利
'Position_function': '', # 职位职能
'position_description': '', # 职位描述
'position_address': '', # 上班地址(详细地址)
}
def get_html(url):
"""
获取页面内容
"""
response = s.get(url, params=payload, headers=header)
html = response.content.decode('GBK')
return html
def load_tree(html):
"""
加载树
"""
global tree
tree = etree.HTML(html)
def extract_list(xpath):
"""
提取满足条件元素内容的列表
"""
item_list = tree.xpath(xpath)
if not item_list:
return []
return item_list
def extract_item(xpath):
"""
提取满足条件的单个内容
"""
item_list = tree.xpath(xpath)
if not item_list:
return None
return item_list[0]
def get_position_url_list():
"""
获取职位列表页中所有职位的链接列表
"""
url_list = extract_list('//table[@id="resultList"]/tr[@class="tr0"]/td[@class="td1"]/a/@href')
print url_list
print '单页职位数:%s' % len(url_list)
def get_next_page():
"""
获取下一页链接
"""
url = extract_item('//table[@class="searchPageNav"]/tr/td[last()]/a/@href')
print url
return url
def get_list():
pass
def get_detail():
pass
def fuck():
# 指定每个条件列表页面
fetch_page_num_per_condition = 10
load_tree(get_html(url_root))
get_position_url_list()
url_next = get_next_page()
# 取前10页
for i in xrange(fetch_page_num_per_condition-2):
load_tree(get_html(url_next))
get_position_url_list()
url_next = get_next_page()
if __name__ == '__main__':
fuck()
"""
分析页面:
职位搜索页面
http://search.51job.com/jobsearch/search_result.php?fromJs=1&jobarea=010000&funtype=0000&industrytype=00&issuedate=8&providesalary=99&keywordtype=1&lang=c&stype=2&workyear=99&cotype=99°reefrom=99&jobterm=01&companysize=99&fromType=1
http://search.51job.com/jobsearch/search_result.php?
fromJs=1
jobarea=010000
funtype=0000
industrytype=00
issuedate=8
providesalary=99
keywordtype=1
lang=c
stype=2
workyear=99
cotype=99
degreefrom=99
jobterm=01
companysize=99
fromType=1
第一页:
http://search.51job.com/jobsearch/search_result.php?fromJs=1&jobarea=010000&funtype=1101&industrytype=00&issuedate=3&lang=c&fromType=18
http://search.51job.com/jobsearch/search_result.php?fromJs=1&jobarea=010000%2C00&district=000000&funtype=1101&industrytype=00&issuedate=3&providesalary=99&keywordtype=1&curr_page=1&lang=c&stype=1&postchannel=0000&workyear=99&cotype=99°reefrom=99&jobterm=01&companysize=99&lonlat=0%2C0&radius=-1&ord_field=0&list_type=0&fromType=14&dibiaoid=-1
第二页:
http://search.51job.com/jobsearch/search_result.php?fromJs=1&jobarea=010000%2C00&district=000000&funtype=1101&industrytype=00&issuedate=3&providesalary=99&keywordtype=1&curr_page=2&lang=c&stype=1&postchannel=0000&workyear=99&cotype=99°reefrom=99&jobterm=01&companysize=99&lonlat=0%2C0&radius=-1&ord_field=0&list_type=0&fromType=14&dibiaoid=-1
第三页:
http://search.51job.com/jobsearch/search_result.php?fromJs=1&jobarea=010000%2C00&district=000000&funtype=1101&industrytype=00&issuedate=3&providesalary=99&keywordtype=1&curr_page=3&lang=c&stype=1&postchannel=0000&workyear=99&cotype=99°reefrom=99&jobterm=01&companysize=99&lonlat=0%2C0&radius=-1&ord_field=0&list_type=0&fromType=14&dibiaoid=-1
"""