自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Python數(shù)據(jù)可視化:淺談數(shù)據(jù)分析崗

大數(shù)據(jù) 數(shù)據(jù)可視化 數(shù)據(jù)分析
本次通過對BOSS直聘,拉勾網(wǎng)數(shù)據(jù)分析崗數(shù)據(jù)分析,了解數(shù)據(jù)分析崗的行業(yè)情況,也以此來了解從事數(shù)據(jù)分析所需要的技能。

有態(tài)度地學習

講道理,pyspider確實是一款優(yōu)秀的爬蟲框架,我們可以利用它快速方便地實現(xiàn)一個頁面的抓取。

不過帶來便捷性的同時,也有它的局限性,復雜頁面不好爬取。

在本次的數(shù)據(jù)爬取中,BOSS直聘是成功使用pyspider。但拉勾網(wǎng)卻不行,因為拉勾網(wǎng)的數(shù)據(jù)是Ajax加載的。

拉勾網(wǎng)崗位數(shù)據(jù)請求的網(wǎng)址是不變的,改變的是表單數(shù)據(jù),表單數(shù)據(jù)隨著頁數(shù)改變,請求方式為POST。這里沒辦法在pyspider里用循環(huán)遍歷來獲取每一頁的數(shù)據(jù)。

也許是我對pyspider框架了解的不夠,還達不到得心應(yīng)手。所以***拉勾網(wǎng)的爬取,采用平常的辦法,在PyCharm中自行編寫程序。

本次通過對BOSS直聘,拉勾網(wǎng)數(shù)據(jù)分析崗數(shù)據(jù)分析,了解數(shù)據(jù)分析崗的行業(yè)情況,也以此來了解從事數(shù)據(jù)分析所需要的技能。

一、網(wǎng)頁分析

Python數(shù)據(jù)可視化:淺談數(shù)據(jù)分析崗

獲取BOSS直聘索引頁信息,主要是崗位名稱、薪資、地點、工作年限、學歷要求,公司名稱、類型、狀態(tài)、規(guī)模。

本來一開始是想對詳情頁分析的,還可以獲取詳情頁里的工作內(nèi)容和工作技能需求。

然后由于請求太多,就放棄了。索引頁有10頁,1頁有30個崗位,一個詳情頁就需要一個請求,算起來一共有300個請求。

我是到了第2頁(60個請求),就出現(xiàn)了訪問過于頻繁的警告。

而只獲取索引頁信息的話,只有10個請求,基本上沒什么問題,外加也不想去鼓搗代理IP,所以來點簡單的。

到時候做數(shù)據(jù)挖掘崗位的數(shù)據(jù)時,看看放慢時間能否獲取成功。

Python數(shù)據(jù)可視化:淺談數(shù)據(jù)分析崗

獲取拉勾網(wǎng)索引頁信息,主要是崗位名稱、地點、薪資、工作年限、學歷要求,公司名稱、類型、狀態(tài)、規(guī)模,工作技能,工作福利。

網(wǎng)頁為Ajax請求,采用PyCharm編寫代碼,輕車熟路。

二、數(shù)據(jù)獲取

01 pyspider獲取BOSS直聘數(shù)據(jù)

pyspider的安裝很簡單,直接在命令行pip3 install pyspider即可。

這里因為之前沒有安裝pyspider對接的PhantomJS(處理JavaScript渲染的頁面)。

所以需要從網(wǎng)站下載下來它的exe文件,將其放入Python的exe文件所在的文件夾下。

***在命令行輸入pyspider all,即可運行pyspider。

在瀏覽器打開網(wǎng)址http://localhost:5000/,創(chuàng)建項目,添加項目名稱,輸入請求網(wǎng)址,得到如下圖。

Python數(shù)據(jù)可視化:淺談數(shù)據(jù)分析崗

***在pyspider的腳本編輯器里編寫代碼,結(jié)合左邊的反饋情況,對代碼加以改正。

Python數(shù)據(jù)可視化:淺談數(shù)據(jù)分析崗

腳本編輯器具體代碼如下。

  1. #!/usr/bin/env python 
  2. # -*- encoding: utf-8 -*- 
  3. # Project: BOSS 
  4.  
  5. from pyspider.libs.base_handler import * 
  6. import pymysql 
  7. import random 
  8. import time 
  9. import re 
  10.  
  11. count = 0 
  12.  
  13. class Handler(BaseHandler): 
  14.     # 添加請求頭,否則出現(xiàn)403報錯 
  15.     crawl_config = {'headers': {'User-Agent''Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'}} 
  16.  
  17.     def __init__(self): 
  18.         # 連接數(shù)據(jù)庫 
  19.         self.db = pymysql.connect(host='127.0.0.1'user='root'password='774110919', port=3306, db='boss_job', charset='utf8mb4'
  20.  
  21.     def add_Mysql(self, id, job_title, job_salary, job_city, job_experience, job_education, company_name, company_type, company_status, company_people): 
  22.         # 將數(shù)據(jù)寫入數(shù)據(jù)庫中 
  23.         try: 
  24.             cursor = self.db.cursor() 
  25.             sql = 'insert into job(id, job_title, job_salary, job_city, job_experience, job_education, company_name, company_type, company_status, company_people) values ("%d", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s")' % (id, job_title, job_salary, job_city, job_experience, job_education, company_name, company_type, company_status, company_people); 
  26.             print(sql) 
  27.             cursor.execute(sql) 
  28.             print(cursor.lastrowid) 
  29.             self.db.commit() 
  30.         except Exception as e: 
  31.             print(e) 
  32.             self.db.rollback() 
  33.  
  34.     @every(minutes=24 * 60) 
  35.     def on_start(self): 
  36.         # 因為pyspider默認是HTTP請求,對于HTTPS(加密)請求,需要添加validate_cert=False,否則599/SSL報錯 
  37.         self.crawl('https://www.zhipin.com/job_detail/?query=%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90&scity=100010000&industry=&position=', callback=self.index_page, validate_cert=False
  38.  
  39.     @config(age=10 * 24 * 60 * 60) 
  40.     def index_page(self, response): 
  41.         time.sleep(random.randint(2, 5)) 
  42.         for i in response.doc('li > div').items(): 
  43.             # 設(shè)置全局變量 
  44.             global count 
  45.             count += 1 
  46.             # 崗位名稱 
  47.             job_title = i('.job-title').text() 
  48.             print(job_title) 
  49.             # 崗位薪水 
  50.             job_salary = i('.red').text() 
  51.             print(job_salary) 
  52.             # 崗位地點 
  53.             city_result = re.search('(.*?)<em class=', i('.info-primary > p').html()) 
  54.             job_city = city_result.group(1).split(' ')[0] 
  55.             print(job_city) 
  56.             # 崗位經(jīng)驗 
  57.             experience_result = re.search('<em class="vline"/>(.*?)<em class="vline"/>', i('.info-primary > p').html()) 
  58.             job_experience = experience_result.group(1) 
  59.             print(job_experience) 
  60.             # 崗位學歷 
  61.             job_education = i('.info-primary > p').text().replace(' ''').replace(city_result.group(1).replace(' '''), '').replace(experience_result.group(1).replace(' '''),''
  62.             print(job_education) 
  63.             # 公司名稱 
  64.             company_name = i('.info-company a').text() 
  65.             print(company_name) 
  66.             # 公司類型 
  67.             company_type_result = re.search('(.*?)<em class=', i('.info-company p').html()) 
  68.             company_type = company_type_result.group(1) 
  69.             print(company_type) 
  70.             # 公司狀態(tài) 
  71.             company_status_result = re.search('<em class="vline"/>(.*?)<em class="vline"/>', i('.info-company p').html()) 
  72.             if company_status_result: 
  73.                 company_status = company_status_result.group(1) 
  74.             else
  75.                 company_status = '無信息' 
  76.             print(company_status) 
  77.             # 公司規(guī)模 
  78.             company_people = i('.info-company p').text().replace(company_type, '').replace(company_status,''
  79.             print(company_people + '\n'
  80.             # 寫入數(shù)據(jù)庫中 
  81.             self.add_Mysql(count, job_title, job_salary, job_city, job_experience, job_education, company_name, company_type, company_status, company_people) 
  82.         # 獲取下一頁信息 
  83.         next = response.doc('.next').attr.href 
  84.         if next != 'javascript:;'
  85.             self.crawl(next, callback=self.index_page, validate_cert=False
  86.         else
  87.             print("The Work is Done"
  88.         # 詳情頁信息獲取,由于訪問次數(shù)有限制,不使用 
  89.         #for each in response.doc('.name > a').items(): 
  90.             #url = each.attr.href 
  91.             #self.crawl(each.attr.href, callback=self.detail_page, validate_cert=False
  92.  
  93.     @config(priority=2) 
  94.     def detail_page(self, response): 
  95.         # 詳情頁信息獲取,由于訪問次數(shù)有限制,不使用 
  96.         message_job = response.doc('div > .info-primary > p').text() 
  97.         city_result = re.findall('城市:(.*?)經(jīng)驗', message_job) 
  98.         experience_result = re.findall('經(jīng)驗:(.*?)學歷', message_job) 
  99.         education_result = re.findall('學歷:(.*)', message_job) 
  100.  
  101.         message_company = response.doc('.info-company > p').text().replace(response.doc('.info-company > p > a').text(),''
  102.         status_result = re.findall('(.*?)\d', message_company.split(' ')[0]) 
  103.         people_result = message_company.split(' ')[0].replace(status_result[0], ''
  104.  
  105.         return { 
  106.             "job_title": response.doc('h1').text(), 
  107.             "job_salary": response.doc('.info-primary .badge').text(), 
  108.             "job_city": city_result[0], 
  109.             "job_experience": experience_result[0], 
  110.             "job_education": education_result[0], 
  111.             "job_skills": response.doc('.info-primary > .job-tags > span').text(), 
  112.             "job_detail": response.doc('div').filter('.text').eq(0).text().replace('\n'''), 
  113.             "company_name": response.doc('.info-company > .name > a').text(), 
  114.             "company_status": status_result[0], 
  115.             "company_people": people_result, 
  116.             "company_type": response.doc('.info-company > p > a').text(), 
  117.         } 

獲取BOSS直聘數(shù)據(jù)分析崗數(shù)據(jù)如下。

Python數(shù)據(jù)可視化:淺談數(shù)據(jù)分析崗

02 PyCharm獲取拉勾網(wǎng)數(shù)據(jù)

  1. import requests 
  2. import pymysql 
  3. import random 
  4. import time 
  5. import json 
  6.  
  7. count = 0 
  8. # 設(shè)置請求網(wǎng)址及請求頭參數(shù) 
  9. url = 'https://www.lagou.com/jobs/positionAjax.json?needAddtionalResult=false' 
  10. headers = { 
  11.     'User-Agent''Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'
  12.     'Cookie''你的Cookie值'
  13.     'Accept''application/json, text/javascript, */*; q=0.01'
  14.     'Connection''keep-alive'
  15.     'Host''www.lagou.com'
  16.     'Origin''https://www.lagou.com'
  17.     'Referer''ttps://www.lagou.com/jobs/list_%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90?labelWords=sug&fromSearch=true&suginput=shuju' 
  18.  
  19. # 連接數(shù)據(jù)庫 
  20. db = pymysql.connect(host='127.0.0.1'user='root'password='774110919', port=3306, db='lagou_job', charset='utf8mb4'
  21.  
  22.  
  23. def add_Mysql(id, job_title, job_salary, job_city, job_experience, job_education, company_name, company_type, company_status, company_people, job_tips, job_welfare): 
  24.     # 將數(shù)據(jù)寫入數(shù)據(jù)庫中 
  25.     try: 
  26.         cursor = db.cursor() 
  27.         sql = 'insert into job(id, job_title, job_salary, job_city, job_experience, job_education, company_name, company_type, company_status, company_people, job_tips, job_welfare) values ("%d", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s")' % (id, job_title, job_salary, job_city, job_experience, job_education, company_name, company_type, company_status, company_people, job_tips, job_welfare); 
  28.         print(sql) 
  29.         cursor.execute(sql) 
  30.         print(cursor.lastrowid) 
  31.         db.commit() 
  32.     except Exception as e: 
  33.         print(e) 
  34.         db.rollback() 
  35.  
  36.  
  37. def get_message(): 
  38.     for i in range(1, 31): 
  39.         print('第' + str(i) + '頁'
  40.         time.sleep(random.randint(10, 20)) 
  41.         data = { 
  42.             'first''false'
  43.             'pn': i, 
  44.             'kd''數(shù)據(jù)分析' 
  45.         } 
  46.         response = requests.post(url=url, data=data, headers=headers) 
  47.         result = json.loads(response.text) 
  48.         job_messages = result['content']['positionResult']['result'
  49.         for job in job_messages: 
  50.             global count 
  51.             count += 1 
  52.             # 崗位名稱 
  53.             job_title = job['positionName'
  54.             print(job_title) 
  55.             # 崗位薪水 
  56.             job_salary = job['salary'
  57.             print(job_salary) 
  58.             # 崗位地點 
  59.             job_city = job['city'
  60.             print(job_city) 
  61.             # 崗位經(jīng)驗 
  62.             job_experience = job['workYear'
  63.             print(job_experience) 
  64.             # 崗位學歷 
  65.             job_education = job['education'
  66.             print(job_education) 
  67.             # 公司名稱 
  68.             company_name = job['companyShortName'
  69.             print(company_name) 
  70.             # 公司類型 
  71.             company_type = job['industryField'
  72.             print(company_type) 
  73.             # 公司狀態(tài) 
  74.             company_status = job['financeStage'
  75.             print(company_status) 
  76.             # 公司規(guī)模 
  77.             company_people = job['companySize'
  78.             print(company_people) 
  79.             # 工作技能 
  80.             if len(job['positionLables']) > 0: 
  81.                 job_tips = ','.join(job['positionLables']) 
  82.             else
  83.                 job_tips = 'None' 
  84.             print(job_tips) 
  85.             # 工作福利 
  86.             job_welfare = job['positionAdvantage'
  87.             print(job_welfare + '\n\n'
  88.             # 寫入數(shù)據(jù)庫 
  89.             add_Mysql(count, job_title, job_salary, job_city, job_experience, job_education, company_name, company_type, company_status, company_people, job_tips, job_welfare) 
  90.  
  91.  
  92. if __name__ == '__main__'
  93.     get_message() 

獲取拉勾網(wǎng)數(shù)據(jù)分析崗數(shù)據(jù)如下。

Python數(shù)據(jù)可視化:淺談數(shù)據(jù)分析崗

這里的數(shù)據(jù)庫都是自己在外面創(chuàng)建的,之前也用了好多回,就不貼代碼細說了。

三、數(shù)據(jù)可視化

01 城市分布圖

Python數(shù)據(jù)可視化:淺談數(shù)據(jù)分析崗

Python數(shù)據(jù)可視化:淺談數(shù)據(jù)分析崗

崗位的分布情況,這里可以看出崗位大多都分布在東部地區(qū),中部也有一些。

02 城市分布熱力圖

Python數(shù)據(jù)可視化:淺談數(shù)據(jù)分析崗

Python數(shù)據(jù)可視化:淺談數(shù)據(jù)分析崗

京津冀、長三角、珠三角密集度不相上下,成都重慶地區(qū)也有一小些需求。

可以說北上廣深,這四個一線城市包攬了大部分的崗位需求。

03 工作經(jīng)驗薪水圖

Python數(shù)據(jù)可視化:淺談數(shù)據(jù)分析崗

Python數(shù)據(jù)可視化:淺談數(shù)據(jù)分析崗

這里通過看箱形圖的四分位及中間值,大致能看出隨著工作年限的增長,薪資也是一路上升。

BOSS直聘里,1年以內(nèi)工作經(jīng)驗的薪資,有個***4萬多的,這肯定是不合理的。

于是就去數(shù)據(jù)庫看了下,其實那個崗位要求是3年以上,但實際給的標簽卻是1年以內(nèi)。

所以說數(shù)據(jù)來源提供的數(shù)據(jù)的準確性很重要。

04 學歷薪水圖

Python數(shù)據(jù)可視化:淺談數(shù)據(jù)分析崗

Python數(shù)據(jù)可視化:淺談數(shù)據(jù)分析崗

總的來說「碩士」>「本科」>「大?!?,當然大專、本科中也有高薪水的。

畢竟越往后能力就越重要,學歷算是一個重要的加分項。

05 公司狀態(tài)薪水圖

Python數(shù)據(jù)可視化:淺談數(shù)據(jù)分析崗

Python數(shù)據(jù)可視化:淺談數(shù)據(jù)分析崗

這里的數(shù)據(jù)沒什么特點,就當了解下這些概念。

一個公司的發(fā)展,可以是從「天使輪」一直到「上市公司」,路途坎坷。

06 公司規(guī)模薪水圖

Python數(shù)據(jù)可視化:淺談數(shù)據(jù)分析崗

Python數(shù)據(jù)可視化:淺談數(shù)據(jù)分析崗

正常來說,公司規(guī)模越大,薪水應(yīng)該會越高。

畢竟大廠的工資擺在那里,想不知道都難。

不過這里沒能體現(xiàn)出來差距,倒是發(fā)現(xiàn)人數(shù)最少的公司,***工資給的不高,難不成是初期缺錢?

07 公司類型***0

Python數(shù)據(jù)可視化:淺談數(shù)據(jù)分析崗

Python數(shù)據(jù)可視化:淺談數(shù)據(jù)分析崗

數(shù)據(jù)分析崗主要集中在互聯(lián)網(wǎng)行業(yè),「金融」「地產(chǎn)」「教育」「醫(yī)療」「游戲」也有所涉及。

大部分崗位需求都集中第三產(chǎn)業(yè)上。

08 工作技能圖

Python數(shù)據(jù)可視化:淺談數(shù)據(jù)分析崗

這個算是本次的重點,這些技能將會是日后學習的重點。

「數(shù)據(jù)挖掘」「SQL」「BI」「數(shù)據(jù)運營」「SPSS」「數(shù)據(jù)庫」「MySQL」等等。

09 工作福利圖

Python數(shù)據(jù)可視化:淺談數(shù)據(jù)分析崗

這里可以看出大部分重點都圍繞著「五險一金」「福利多」「團隊氛圍好」「晉升空間大」「行業(yè)大牛領(lǐng)頭」上。

要是哪家公司都具備了,那簡直就是要上天。

不過你我都清楚,這是不存在的,就算可能存在,也只是別人家的公司而已~

四、總結(jié)

***貼兩張BOSS直聘以及拉勾網(wǎng)薪水TOP20,以此來作為勉勵。

01 BOSS直聘薪水TOP20

Python數(shù)據(jù)可視化:淺談數(shù)據(jù)分析崗

02 拉勾網(wǎng)薪水TOP20

Python數(shù)據(jù)可視化:淺談數(shù)據(jù)分析崗

畢竟我們不能僅僅當條咸魚,我們要當就當一只有夢想的咸魚!!!

責任編輯:未麗燕 來源: 法納斯得
相關(guān)推薦

2017-01-12 17:28:59

數(shù)據(jù)分析數(shù)據(jù)可視化可視化

2020-05-14 10:19:23

Python可視化分析

2017-03-09 09:54:13

分析數(shù)據(jù)可視化

2017-09-15 10:23:06

可視化Bug數(shù)據(jù)分析

2023-11-24 14:02:00

Python數(shù)據(jù)分析

2020-07-14 16:08:33

數(shù)據(jù)分析Python筆試

2017-04-18 11:01:14

數(shù)據(jù)分析數(shù)據(jù)可視化

2019-09-02 15:40:25

可視化數(shù)據(jù)分析

2023-08-28 16:19:32

2020-03-11 14:39:26

數(shù)據(jù)可視化地圖可視化地理信息

2021-10-11 08:04:22

Python數(shù)據(jù)行程

2018-11-21 14:38:09

分析在數(shù)據(jù)電影

2017-10-14 13:54:26

數(shù)據(jù)可視化數(shù)據(jù)信息可視化

2016-12-29 20:05:56

數(shù)據(jù)可視化大數(shù)據(jù)產(chǎn)品分析

2024-07-01 08:51:19

可視化數(shù)據(jù)分析漏斗

2020-12-07 05:51:49

數(shù)據(jù)分析數(shù)據(jù)可視化數(shù)據(jù)科學

2019-10-10 17:40:54

數(shù)據(jù)科學可視化繪圖

2022-02-23 09:50:52

PythonEchartspyecharts

2020-05-26 11:34:46

可視化WordCloud

2016-08-11 16:30:14

數(shù)據(jù)分析 BI 數(shù)據(jù)分析工具
點贊
收藏

51CTO技術(shù)棧公眾號