# wajue_final **Repository Path**: bakasui/wajue_final ## Basic Information - **Project Name**: wajue_final - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-07-19 - **Last Updated**: 2024-10-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README
import requests
import time# 加载所需模块
def headers_to_dict(headers):
headers = headers.split("\n")
d_headers = dict()
for h in headers:
if h:
k, v = h.split(":", 1)
if k == 'cookie' and d_headers.get(k, None) is not None:
d_headers[k] = d_headers.get(k) + "; " + v.strip()
else:
d_headers[k] = v.strip()
return d_headers
import urllib3 # 此模块用于解决警告弹出问题
urllib3.disable_warnings()
home_url = 'https://www.lagou.com/jobs/list_%E6%96%87%E6%A1%88?city=%E5%B9%BF%E5%B7%9E'# 需要爬取的url
url = 'https://www.lagou.com/jobs/positionAjax.json?px=new&needAddtionalResult=false'
headers = """
accept: application/json, text/javascript, */*; q=0.01
origin: https://www.lagou.com
referer: https://www.lagou.com/jobs/list_%E6%96%87%E6%A1%88?city=%E5%B9%BF%E5%B7%9E
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
""" # 使用网站的headers信息 伪装成客户端来爬取数据
headers_dict = headers_to_dict(headers)
def get_data_from_cloud(page):# 设置爬取参数
params = {
'first': 'false',
'pn': page,
'kd': '文案'
}
s = requests.Session() # 创建一个session对象
s.get(home_url, headers=headers_dict, timeout=5) # 用session对象发出get请求,请求首页获取cookies
cookie = s.cookies # 为此次获取的cookies
response = requests.post(url, data=params, headers=headers_dict, cookies=cookie, timeout=3,verify= False)
result = response.text
write_file(result)
def write_file(content):
filename = '文案.txt'# 设置输出文件的名称和格式
with open(filename, 'a',encoding='utf-8') as f:
f.write(content + '\n')
def get_data():
for i in range(76):# 所爬取的数据页数,分行业部分根据各行业筛选结果实际页面数调整
page = i + 1
get_data_from_cloud(page)
time.sleep(10)# 设置爬取间隔时间,根据爬取量的不同调整
get_data()
图上红圈部分为我划分的传统文案相关行业

图上蓝圈部分为我划分的网新相关行业

home_url = 'https://www.lagou.com/jobs/list_%E6%96%87%E6%A1%88/p-city_213?hy=%E7%A7%BB%E5%8A%A8%E4%BA%92%E8%81%94%E7%BD%91'
url = 'https://www.lagou.com/jobs/positionAjax.json?px=new&needAddtionalResult=false'
headers = """
accept: application/json, text/javascript, */*; q=0.01
origin: https://www.lagou.com
referer: https://www.lagou.com/jobs/list_%E6%96%87%E6%A1%88/p-city_213?hy=%E7%A7%BB%E5%8A%A8%E4%BA%92%E8%81%94%E7%BD%91
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
"""
headers_dict = headers_to_dict(headers)
def get_data_from_cloud(page):
params = {
'first': 'false',
'pn': page,
'kd': '文案'
}
s = requests.Session() # 创建一个session对象
s.get(home_url, headers=headers_dict, timeout=5) # 用session对象发出get请求,请求首页获取cookies
cookie = s.cookies # 为此次获取的cookies
response = requests.post(url, data=params, headers=headers_dict, cookies=cookie, timeout=3,verify= False)
result = response.text
write_file(result)
def write_file(content):
filename = '移动互联网分类.txt'
with open(filename, 'a',encoding='utf-8') as f:
f.write(content + '\n')
def get_data():
for i in range(11):
page = i + 1
get_data_from_cloud(page)
time.sleep(8)
get_data()
home_url = 'https://www.lagou.com/jobs/list_%E6%96%87%E6%A1%88/p-city_213?hy=%E6%96%87%E5%A8%B1%E4%B8%A8%E5%86%85%E5%AE%B9'
url = 'https://www.lagou.com/jobs/positionAjax.json?px=new&needAddtionalResult=false'
headers = """
accept: application/json, text/javascript, */*; q=0.01
origin: https://www.lagou.com
referer: https://www.lagou.com/jobs/list_%E6%96%87%E6%A1%88/p-city_213?hy=%E6%96%87%E5%A8%B1%E4%B8%A8%E5%86%85%E5%AE%B9
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
"""
headers_dict = headers_to_dict(headers)
def get_data_from_cloud(page):
params = {
'first': 'false',
'pn': page,
'kd': '文案'
}
s = requests.Session() # 创建一个session对象
s.get(home_url, headers=headers_dict, timeout=5) # 用session对象发出get请求,请求首页获取cookies
cookie = s.cookies # 获取的cookies
response = requests.post(url, data=params, headers=headers_dict, cookies=cookie, timeout=3,verify= False)
result = response.text
write_file(result)
def write_file(content):
filename = '文娱内容分类.txt'
with open(filename, 'a',encoding='utf-8') as f:
f.write(content + '\n')
def get_data():
for i in range(17):
page = i + 1
get_data_from_cloud(page)
time.sleep(8)
get_data()
home_url = 'https://www.lagou.com/jobs/list_%E6%96%87%E6%A1%88/p-city_213?hy=%E5%B9%BF%E5%91%8A%E8%90%A5%E9%94%80'
url = 'https://www.lagou.com/jobs/positionAjax.json?px=new&needAddtionalResult=false'
headers = """
accept: application/json, text/javascript, */*; q=0.01
origin: https://www.lagou.com
referer: https://www.lagou.com/jobs/list_%E6%96%87%E6%A1%88/p-city_213?hy=%E5%B9%BF%E5%91%8A%E8%90%A5%E9%94%80
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
"""
headers_dict = headers_to_dict(headers)
def get_data_from_cloud(page):
params = {
'first': 'false',
'pn': page,
'kd': '文案'
}
s = requests.Session() # 创建一个session对象
s.get(home_url, headers=headers_dict, timeout=5) # 用session对象发出get请求,请求首页获取cookies
cookie = s.cookies # 为此次获取的cookies
response = requests.post(url, data=params, headers=headers_dict, cookies=cookie, timeout=3,verify= False)
result = response.text
write_file(result)
def write_file(content):
filename = '广告营销分类.txt'
with open(filename, 'a',encoding='utf-8') as f:
f.write(content + '\n')
def get_data():
for i in range(7):
page = i + 1
get_data_from_cloud(page)
time.sleep(8)
get_data()
home_url = 'https://www.lagou.com/jobs/list_%E6%96%87%E6%A1%88/p-city_213?hy=%E7%94%B5%E5%95%86'
url = 'https://www.lagou.com/jobs/positionAjax.json?px=new&needAddtionalResult=false'
headers = """
accept: application/json, text/javascript, */*; q=0.01
origin: https://www.lagou.com
referer: https://www.lagou.com/jobs/list_%E6%96%87%E6%A1%88/p-city_213?hy=%E7%94%B5%E5%95%86
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
"""
headers_dict = headers_to_dict(headers)
def get_data_from_cloud(page):
params = {
'first': 'false',
'pn': page,
'kd': '文案'
}
s = requests.Session() # 创建一个session对象
s.get(home_url, headers=headers_dict, timeout=5) # 用session对象发出get请求,请求首页获取cookies
cookie = s.cookies # 为此次获取的cookies
response = requests.post(url, data=params, headers=headers_dict, cookies=cookie, timeout=3,verify= False)
result = response.text
write_file(result)
def write_file(content):
filename = '电商分类.txt'
with open(filename, 'a',encoding='utf-8') as f:
f.write(content + '\n')
def get_data():
for i in range(10):
page = i + 1
get_data_from_cloud(page)
time.sleep(8)
get_data()
home_url = 'https://www.lagou.com/jobs/list_%E6%96%87%E6%A1%88/p-city_213?hy=%E6%95%B0%E6%8D%AE%E6%9C%8D%E5%8A%A1'
url = 'https://www.lagou.com/jobs/positionAjax.json?px=new&needAddtionalResult=false'
headers = """
accept: application/json, text/javascript, */*; q=0.01
origin: https://www.lagou.com
referer: https://www.lagou.com/jobs/list_%E6%96%87%E6%A1%88/p-city_213?hy=%E6%95%B0%E6%8D%AE%E6%9C%8D%E5%8A%A1
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
"""
headers_dict = headers_to_dict(headers)
def get_data_from_cloud(page):
params = {
'first': 'false',
'pn': page,
'kd': '文案'
}
s = requests.Session() # 创建一个session对象
s.get(home_url, headers=headers_dict, timeout=5) # 用session对象发出get请求,请求首页获取cookies
cookie = s.cookies # 为此次获取的cookies
response = requests.post(url, data=params, headers=headers_dict, cookies=cookie, timeout=3,verify= False)
result = response.text
write_file(result)
def write_file(content):
filename = '数据服务分类.txt'
with open(filename, 'a',encoding='utf-8') as f:
f.write(content + '\n')
def get_data():
for i in range(6):
page = i + 1
get_data_from_cloud(page)
time.sleep(8)
get_data()
home_url = 'https://www.lagou.com/jobs/list_%E6%96%87%E6%A1%88/p-city_213?hy=%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD'
url = 'https://www.lagou.com/jobs/positionAjax.json?px=new&needAddtionalResult=false'
headers = """
accept: application/json, text/javascript, */*; q=0.01
origin: https://www.lagou.com
referer: https://www.lagou.com/jobs/list_%E6%96%87%E6%A1%88/p-city_213?hy=%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
"""
headers_dict = headers_to_dict(headers)
def get_data_from_cloud(page):
params = {
'first': 'false',
'pn': page,
'kd': '文案'
}
s = requests.Session() # 创建一个session对象
s.get(home_url, headers=headers_dict, timeout=5) # 用session对象发出get请求,请求首页获取cookies
cookie = s.cookies # 为此次获取的cookies
response = requests.post(url, data=params, headers=headers_dict, cookies=cookie, timeout=3,verify= False)
result = response.text
write_file(result)
def write_file(content):
filename = '人工智能分类.txt'
with open(filename, 'a',encoding='utf-8') as f:
f.write(content + '\n')
def get_data():
for i in range(1):
page = i + 1
get_data_from_cloud(page)
time.sleep(8)
get_data()
home_url = 'https://www.lagou.com/jobs/list_%E6%96%87%E6%A1%88/p-city_213?hy=%E8%BD%AF%E4%BB%B6%E5%BC%80%E5%8F%91'
url = 'https://www.lagou.com/jobs/positionAjax.json?px=new&needAddtionalResult=false'
headers = """
accept: application/json, text/javascript, */*; q=0.01
origin: https://www.lagou.com
referer: https://www.lagou.com/jobs/list_%E6%96%87%E6%A1%88/p-city_213?hy=%E8%BD%AF%E4%BB%B6%E5%BC%80%E5%8F%91
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
"""
headers_dict = headers_to_dict(headers)
def get_data_from_cloud(page):
params = {
'first': 'false',
'pn': page,
'kd': '文案'
}
s = requests.Session() # 创建一个session对象
s.get(home_url, headers=headers_dict, timeout=5) # 用session对象发出get请求,请求首页获取cookies
cookie = s.cookies # 为此次获取的cookies
response = requests.post(url, data=params, headers=headers_dict, cookies=cookie, timeout=3,verify= False)
result = response.text
write_file(result)
def write_file(content):
filename = '软件开发分类.txt'
with open(filename, 'a',encoding='utf-8') as f:
f.write(content + '\n')
def get_data():
for i in range(4):
page = i + 1
get_data_from_cloud(page)
time.sleep(8)
get_data()
home_url = 'https://www.lagou.com/jobs/list_%E6%96%87%E6%A1%88/p-city_213?hy=%E4%BC%81%E4%B8%9A%E6%9C%8D%E5%8A%A1'
url = 'https://www.lagou.com/jobs/positionAjax.json?px=new&needAddtionalResult=false'
headers = """
accept: application/json, text/javascript, */*; q=0.01
origin: https://www.lagou.com
referer: https://www.lagou.com/jobs/list_%E6%96%87%E6%A1%88/p-city_213?hy=%E4%BC%81%E4%B8%9A%E6%9C%8D%E5%8A%A1
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
"""
headers_dict = headers_to_dict(headers)
def get_data_from_cloud(page):
params = {
'first': 'false',
'pn': page,
'kd': '文案'
}
s = requests.Session() # 创建一个session对象
s.get(home_url, headers=headers_dict, timeout=5) # 用session对象发出get请求,请求首页获取cookies
cookie = s.cookies # 为此次获取的cookies
response = requests.post(url, data=params, headers=headers_dict, cookies=cookie, timeout=3,verify= False)
result = response.text
write_file(result)
def write_file(content):
filename = '企业服务分类.txt'
with open(filename, 'a',encoding='utf-8') as f:
f.write(content + '\n')
def get_data():
for i in range(14):
page = i + 1
get_data_from_cloud(page)
time.sleep(8)
get_data()
%matplotlib inline
import numpy as np # 载入所需模块
from pyecharts import options as opts
from pyecharts.charts import Bar
from pyecharts.charts import Pie
from wordcloud import WordCloud
import matplotlib.pyplot as plt
import json
import pandas as pd
def get_data():
with open('文案.txt',encoding='utf-8') as f:# 打开之前导出的数据文件
data = []
for line in f.readlines():
result = json.loads(line)
result_list = result['content']['positionResult']['result']
for item in result_list:# 构建字典
dict = {
'district': item['district'],
'industryField': item['industryField'],
'education': item['education'],
'workYear': item['workYear'],
'salary': item['salary'],
'firstType': item['firstType'],
'secondType': item['secondType'],
'thirdType': item['thirdType'],
'skillLables': item['skillLables']
}
data.append(dict)
return data
data = get_data()# 调用数据
data = pd.DataFrame(data)
data.head(500)# 显现其中的500条数据以展示分类效果
citys_value_counts = data['district'].value_counts() # 选取区域标签进行整合
top = 20 # 选取前20的地区
citys = list(citys_value_counts.head(top).index)
city_counts = list(citys_value_counts.head(top))
bar = (
Bar()
.add_xaxis(citys)
.add_yaxis("", city_counts)
)
bar.render_notebook()
industrys = list(data['industryField']) # 选取行业标签进行整合
industry_list = [i for item in industrys for i in item.split(',')]
industry_series = pd.Series(data=industry_list)
industry_value_counts = industry_series.value_counts()
industrys = list(industry_value_counts.head(top).index)
industry_counts = list(industry_value_counts.head(top))
pie = ( # 调用pyechart的饼图模块
Pie()
.add("", [list(z) for z in zip(industrys, industry_counts)])
.set_global_opts(title_opts=opts.TitleOpts(title=""))
.set_global_opts(legend_opts=opts.LegendOpts(is_show=False))
)
pie.render_notebook()
eduction_value_counts = data['education'].value_counts() # 选取学历标签进行整合
eduction = list(eduction_value_counts.index)
eduction_counts = list(eduction_value_counts)
pie = (
Pie()
.add("", [list(z) for z in zip(eduction, eduction_counts)])
.set_global_opts(title_opts=opts.TitleOpts(title=""))
.set_global_opts(legend_opts=opts.LegendOpts(is_show=False))
)
pie.render_notebook()
work_year_value_counts = data['workYear'].value_counts() # 工作经验作为标签进行整合
work_year = list(work_year_value_counts.index)
work_year_counts = list(work_year_value_counts)
bar = (
Bar()
.add_xaxis(work_year)
.add_yaxis("", work_year_counts)
)
bar.render_notebook()
salary_value_counts = data['salary'].value_counts() # 选取工资标签进行整合
salary = list(salary_value_counts.head(top).index)
salary_counts = list(salary_value_counts.head(top))
bar = (
Bar()
.add_xaxis(salary)
.add_yaxis("", salary_counts)
.set_global_opts(xaxis_opts=opts.AxisOpts(name_rotate=0, name="薪资", axislabel_opts={"rotate": 45}))
)
bar.render_notebook()
import numpy as np # 载入所需模块
from pyecharts import options as opts
from pyecharts.charts import Bar
from pyecharts.charts import Pie
from wordcloud import WordCloud
import matplotlib.pyplot as plt
import json
import pandas as pd
def get_data():
with open('移动互联网分类.txt',encoding='utf-8') as f: # 选取要分析的行业数据
data = []
for line in f.readlines():
result = json.loads(line)
result_list = result['content']['positionResult']['result']
for item in result_list:
dict = {
'city': item['city'],
'district': item['district'],
'industryField': item['industryField'],
'education': item['education'],
'workYear': item['workYear'],
'salary': item['salary'],
'firstType': item['firstType'],
'secondType': item['secondType'],
'thirdType': item['thirdType'],
'skillLables': item['skillLables']
}
data.append(dict)
return data
data = get_data()
data = pd.DataFrame(data)
salary_value_counts = data['salary'].value_counts()
salary = list(salary_value_counts.head(top).index)
salary_counts = list(salary_value_counts.head(top))
bar = (
Bar()
.add_xaxis(salary)
.add_yaxis("", salary_counts)
.set_global_opts(xaxis_opts=opts.AxisOpts(name_rotate=0, name="薪资", axislabel_opts={"rotate": 45}))
)
bar.render_notebook()
def get_data():
with open('文娱内容分类.txt',encoding='utf-8') as f:
data = []
for line in f.readlines():
result = json.loads(line)
result_list = result['content']['positionResult']['result']
for item in result_list:
dict = {
'city': item['city'],
'district': item['district'],
'industryField': item['industryField'],
'education': item['education'],
'workYear': item['workYear'],
'salary': item['salary'],
'firstType': item['firstType'],
'secondType': item['secondType'],
'thirdType': item['thirdType'],
'skillLables': item['skillLables']
}
data.append(dict)
return data
data = get_data()
data = pd.DataFrame(data)
salary_value_counts = data['salary'].value_counts()
salary = list(salary_value_counts.head(top).index)
salary_counts = list(salary_value_counts.head(top))
bar = (
Bar()
.add_xaxis(salary)
.add_yaxis("", salary_counts)
.set_global_opts(xaxis_opts=opts.AxisOpts(name_rotate=0, name="薪资", axislabel_opts={"rotate": 45}))
)
bar.render_notebook()
def get_data():
with open('广告营销分类.txt',encoding='utf-8') as f:
data = []
for line in f.readlines():
result = json.loads(line)
result_list = result['content']['positionResult']['result']
for item in result_list:
dict = {
'city': item['city'],
'district': item['district'],
'industryField': item['industryField'],
'education': item['education'],
'workYear': item['workYear'],
'salary': item['salary'],
'firstType': item['firstType'],
'secondType': item['secondType'],
'thirdType': item['thirdType'],
'skillLables': item['skillLables']
}
data.append(dict)
return data
data = get_data()
data = pd.DataFrame(data)
salary_value_counts = data['salary'].value_counts()
salary = list(salary_value_counts.head(top).index)
salary_counts = list(salary_value_counts.head(top))
bar = (
Bar()
.add_xaxis(salary)
.add_yaxis("", salary_counts)
.set_global_opts(xaxis_opts=opts.AxisOpts(name_rotate=0, name="薪资", axislabel_opts={"rotate": 45}))
)
bar.render_notebook()
def get_data():
with open('电商分类.txt',encoding='utf-8') as f:
data = []
for line in f.readlines():
result = json.loads(line)
result_list = result['content']['positionResult']['result']
for item in result_list:
dict = {
'city': item['city'],
'district': item['district'],
'industryField': item['industryField'],
'education': item['education'],
'workYear': item['workYear'],
'salary': item['salary'],
'firstType': item['firstType'],
'secondType': item['secondType'],
'thirdType': item['thirdType'],
'skillLables': item['skillLables']
}
data.append(dict)
return data
data = get_data()
data = pd.DataFrame(data)
salary_value_counts = data['salary'].value_counts()
salary = list(salary_value_counts.head(top).index)
salary_counts = list(salary_value_counts.head(top))
bar = (
Bar()
.add_xaxis(salary)
.add_yaxis("", salary_counts)
.set_global_opts(xaxis_opts=opts.AxisOpts(name_rotate=0, name="薪资", axislabel_opts={"rotate": 45}))
)
bar.render_notebook()
def get_data():
with open('企业服务分类.txt',encoding='utf-8') as f:
data = []
for line in f.readlines():
result = json.loads(line)
result_list = result['content']['positionResult']['result']
for item in result_list:
dict = {
'city': item['city'],
'district': item['district'],
'industryField': item['industryField'],
'education': item['education'],
'workYear': item['workYear'],
'salary': item['salary'],
'firstType': item['firstType'],
'secondType': item['secondType'],
'thirdType': item['thirdType'],
'skillLables': item['skillLables']
}
data.append(dict)
return data
data = get_data()
data = pd.DataFrame(data)
salary_value_counts = data['salary'].value_counts()
salary = list(salary_value_counts.head(top).index)
salary_counts = list(salary_value_counts.head(top))
bar = (
Bar()
.add_xaxis(salary)
.add_yaxis("", salary_counts)
.set_global_opts(xaxis_opts=opts.AxisOpts(name_rotate=0, name="薪资", axislabel_opts={"rotate": 45}))
)
bar.render_notebook()
def get_data():
with open('数据服务分类.txt',encoding='utf-8') as f:
data = []
for line in f.readlines():
result = json.loads(line)
result_list = result['content']['positionResult']['result']
for item in result_list:
dict = {
'city': item['city'],
'district': item['district'],
'industryField': item['industryField'],
'education': item['education'],
'workYear': item['workYear'],
'salary': item['salary'],
'firstType': item['firstType'],
'secondType': item['secondType'],
'thirdType': item['thirdType'],
'skillLables': item['skillLables']
}
data.append(dict)
return data
data = get_data()
data = pd.DataFrame(data)
salary_value_counts = data['salary'].value_counts()
salary = list(salary_value_counts.head(top).index)
salary_counts = list(salary_value_counts.head(top))
bar = (
Bar()
.add_xaxis(salary)
.add_yaxis("", salary_counts)
.set_global_opts(xaxis_opts=opts.AxisOpts(name_rotate=0, name="薪资", axislabel_opts={"rotate": 45}))
)
bar.render_notebook()
def get_data():
with open('人工智能分类.txt',encoding='utf-8') as f:
data = []
for line in f.readlines():
result = json.loads(line)
result_list = result['content']['positionResult']['result']
for item in result_list:
dict = {
'city': item['city'],
'district': item['district'],
'industryField': item['industryField'],
'education': item['education'],
'workYear': item['workYear'],
'salary': item['salary'],
'firstType': item['firstType'],
'secondType': item['secondType'],
'thirdType': item['thirdType'],
'skillLables': item['skillLables']
}
data.append(dict)
return data
data = get_data()
data = pd.DataFrame(data)
salary_value_counts = data['salary'].value_counts()
salary = list(salary_value_counts.head(top).index)
salary_counts = list(salary_value_counts.head(top))
bar = (
Bar()
.add_xaxis(salary)
.add_yaxis("", salary_counts)
.set_global_opts(xaxis_opts=opts.AxisOpts(name_rotate=0, name="薪资", axislabel_opts={"rotate": 45}))
)
bar.render_notebook()
def get_data():
with open('软件开发分类.txt',encoding='utf-8') as f:
data = []
for line in f.readlines():
result = json.loads(line)
result_list = result['content']['positionResult']['result']
for item in result_list:
dict = {
'city': item['city'],
'district': item['district'],
'industryField': item['industryField'],
'education': item['education'],
'workYear': item['workYear'],
'salary': item['salary'],
'firstType': item['firstType'],
'secondType': item['secondType'],
'thirdType': item['thirdType'],
'skillLables': item['skillLables']
}
data.append(dict)
return data
data = get_data()
data = pd.DataFrame(data)
salary_value_counts = data['salary'].value_counts()
salary = list(salary_value_counts.head(top).index)
salary_counts = list(salary_value_counts.head(top))
bar = (
Bar()
.add_xaxis(salary)
.add_yaxis("", salary_counts)
.set_global_opts(xaxis_opts=opts.AxisOpts(name_rotate=0, name="薪资", axislabel_opts={"rotate": 45}))
)
bar.render_notebook()