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

Python拉勾網(wǎng)數(shù)據(jù)采集與可視化

大數(shù)據(jù) 數(shù)據(jù)可視化
本文是先采集拉勾網(wǎng)上面的數(shù)據(jù),采集的是Python崗位的數(shù)據(jù),然后用Python進(jìn)行可視化。主要涉及的是爬蟲(chóng)&數(shù)據(jù)可視化的知識(shí)。先用Python來(lái)抓取拉勾網(wǎng)上面的數(shù)據(jù),采用的是簡(jiǎn)單好用的requests模塊。

全文簡(jiǎn)介

本文是先采集拉勾網(wǎng)上面的數(shù)據(jù),采集的是Python崗位的數(shù)據(jù),然后用Python進(jìn)行可視化。主要涉及的是爬蟲(chóng)&數(shù)據(jù)可視化的知識(shí)。

爬蟲(chóng)部分

先用Python來(lái)抓取拉勾網(wǎng)上面的數(shù)據(jù),采用的是簡(jiǎn)單好用的requests模塊。主要注意的地方是,拉勾網(wǎng)屬于動(dòng)態(tài)網(wǎng)頁(yè),所以會(huì)用到瀏覽器的F12開(kāi)發(fā)者工具進(jìn)行抓包。抓包以后會(huì)發(fā)現(xiàn),其實(shí)網(wǎng)頁(yè)是一個(gè)POST的形式,所以要提交數(shù)據(jù),提交的數(shù)據(jù)如下圖:

Python拉勾網(wǎng)數(shù)據(jù)采集與可視化

真實(shí)網(wǎng)址是:https://www.lagou.com/jobs/positionAjax.json?needAddtionalResult=false&isSchoolJob=0

在上圖也可以輕松發(fā)現(xiàn):kd是查詢(xún)關(guān)鍵詞,pn是頁(yè)數(shù),可以實(shí)現(xiàn)翻頁(yè)。

代碼實(shí)現(xiàn)

 

  1. import requests # 網(wǎng)絡(luò)請(qǐng)求 
  2. import re 
  3. import time 
  4. import random 
  5.  
  6. # post的網(wǎng)址 
  7. url = 'https://www.lagou.com/jobs/positionAjax.json?needAddtionalResult=false&isSchoolJob=0' 
  8.  
  9. # 反爬措施 
  10. header = {'Host''www.lagou.com'
  11. 'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36'
  12. 'Accept''application/json, text/javascript, */*; q=0.01'
  13. 'Accept-Language''zh-CN,en-US;q=0.7,en;q=0.3'
  14. 'Accept-Encoding''gzip, deflate, br'
  15. 'Referer''https://www.lagou.com/jobs/list_Python?labelWords=&fromSearch=true&suginput='
  16. 'Content-Type''application/x-www-form-urlencoded; charset=UTF-8'
  17. 'X-Requested-With''XMLHttpRequest'
  18. 'X-Anit-Forge-Token''None'
  19. 'X-Anit-Forge-Code''0'
  20. 'Content-Length''26'
  21. 'Cookie''user_trace_token=20171103191801-9206e24f-9ca2-40ab-95a3-23947c0b972a; _ga=GA1.2.545192972.1509707889; LGUID=20171103191805-a9838dac-c088-11e7-9704-5254005c3644; JSESSIONID=ABAAABAACDBABJB2EE720304E451B2CEFA1723CE83F19CC; _gat=1; LGSID=20171228225143-9edb51dd-ebde-11e7-b670-525400f775ce; PRE_UTM=; PRE_HOST=www.baidu.com; PRE_SITE=https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DKkJPgBHAnny1nUKaLpx2oDfUXv9ItIF3kBAWM2-fDNu%26ck%3D3065.1.126.376.140.374.139.129%26shh%3Dwww.baidu.com%26sht%3Dmonline_3_dg%26wd%3D%26eqid%3Db0ec59d100013c7f000000055a4504f6; PRE_LAND=https%3A%2F%2Fwww.lagou.com%2F; LGRID=20171228225224-b6cc7abd-ebde-11e7-9f67-5254005c3644; index_location_city=%E5%85%A8%E5%9B%BD; TG-TRACK-CODE=index_search; SEARCH_ID=3ec21cea985a4a5fa2ab279d868560c8'
  22. 'Connection''keep-alive'
  23. 'Pragma''no-cache'
  24. 'Cache-Control''no-cache'
  25.  
  26. for n in range(30): 
  27.      
  28.     # 要提交的數(shù)據(jù) 
  29.     form = {'first':'false'
  30.             'kd':'Python'
  31.             'pn':str(n)} 
  32.      
  33.     time.sleep(random.randint(2,5)) 
  34.      
  35.     # 提交數(shù)據(jù) 
  36.     html = requests.post(url,data=form,headers = header) 
  37.      
  38.     # 提取數(shù)據(jù) 
  39.     data = re.findall('{"companyId":.*?,"positionName":"(.*?)","workYear":"(.*?)","education":"(.*?)","jobNature":"(.*?)","financeStage":"(.*?)","companyLogo":".*?","industryField":".*?","city":"(.*?)","salary":"(.*?)","positionId":.*?,"positionAdvantage":"(.*?)","companyShortName":"(.*?)","district"',html.text) 
  40.      
  41.     # 轉(zhuǎn)換成數(shù)據(jù)框 
  42.      
  43.     data = pd.DataFrame(data) 
  44.      
  45.     # 保存在本地 
  46.     data.to_csv(r'D:\Windows 7 Documents\Desktop\My\LaGouDataMatlab.csv',header = Falseindex = False, mode = 'a+'
  47.      

注意:抓取數(shù)據(jù)的時(shí)候不要爬取太快,除非你有其他的反爬措施,比如更換IP等,另外不需登錄,我在代碼加入了time模塊,用于限制爬取速度。

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

下載下來(lái)的數(shù)據(jù)長(zhǎng)成這個(gè)樣子: 

 

Python拉勾網(wǎng)數(shù)據(jù)采集與可視化

注意標(biāo)題(也就是列明)是我自己添加的。

導(dǎo)入模塊并配置繪圖風(fēng)格

 

  1. import pandas as pd # 數(shù)據(jù)框操作 
  2. import numpy as np  
  3. import matplotlib.pyplot as plt # 繪圖 
  4. import jieba # 分詞 
  5. from wordcloud import WordCloud # 詞云可視化 
  6. import matplotlib as mpl  # 配置字體 
  7. from pyecharts import Geo # 地理圖 
  8.  
  9. mpl.rcParams["font.sans-serif"] = ["Microsoft YaHei"
  10. # 配置繪圖風(fēng)格 
  11. plt.rcParams["axes.labelsize"] = 16.    
  12. plt.rcParams["xtick.labelsize"] = 14. 
  13. plt.rcParams["ytick.labelsize"] = 14. 
  14. plt.rcParams["legend.fontsize"] = 12. 
  15. plt.rcParams["figure.figsize"] = [15., 15.] 

注意:導(dǎo)入模塊的時(shí)候其他都容易解決,除了wordcloud這個(gè)模塊,這個(gè)模塊我建議大家手動(dòng)安裝,如果pip安裝的話,會(huì)提示你缺少C++14.0之類(lèi)的錯(cuò)誤,導(dǎo)致安裝不上。手動(dòng)下載whl文件就可以順利安裝了。

數(shù)據(jù)預(yù)覽

 

  1. # 導(dǎo)入數(shù)據(jù) 
  2. data = pd.read_csv('D:\\Windows 7 Documents\\Desktop\\My\\LaGouDataPython.csv',encoding='gbk')  # 導(dǎo)入數(shù)據(jù) 
  3. data.head() 

 Python拉勾網(wǎng)數(shù)據(jù)采集與可視化

read_csv路徑不要帶有中文

  1. data.tail() 

 Python拉勾網(wǎng)數(shù)據(jù)采集與可視化

學(xué)歷要求

 

  1. data['學(xué)歷要求'].value_counts().plot(kind='barh',rot=0)  
  2. plt.show() 

 Python拉勾網(wǎng)數(shù)據(jù)采集與可視化

工作經(jīng)驗(yàn)

 

  1. data['工作經(jīng)驗(yàn)'].value_counts().plot(kind='bar',rot=0,color='b'
  2. plt.show() 

Python拉勾網(wǎng)數(shù)據(jù)采集與可視化

Python熱門(mén)崗位

 

  1. final = ''   
  2. stopwords = ['PYTHON','python','Python','工程師','(',')','/'] # 停止詞 
  3. for n in range(data.shape[0]): 
  4.      
  5.     seg_list = list(jieba.cut(data['崗位職稱(chēng)'][n])) 
  6.     
  7.     for seg in seg_list:   
  8.         if seg not in stopwords:   
  9.                 final = final + seg + ' ' 
  10. # final 得到的詞匯 

Python拉勾網(wǎng)數(shù)據(jù)采集與可視化

工作地點(diǎn)

  1. data['工作地點(diǎn)'].value_counts().plot(kind='pie',autopct='%1.2f%%',explode = np.linspace(0,1.5,25))  
  2. plt.show() 

Python拉勾網(wǎng)數(shù)據(jù)采集與可視化

 

工作地理圖 

  1. # 提取數(shù)據(jù)框 
  2. data2 = list(map(lambda x:(data['工作地點(diǎn)'][x],eval(re.split('k|K',data['工資'][x])[0])*1000),range(len(data)))) 
  3. # 提取價(jià)格信息 
  4. data3 = pd.DataFrame(data2) 
  5. # 轉(zhuǎn)化成Geo需要的格式 
  6. data4 = list(map(lambda x:(data3.groupby(0).mean()[1].index[x],data3.groupby(0).mean()[1].values[x]),range(len(data3.groupby(0))))) 
  7. # 地理位置展示 
  8. geo = Geo("全國(guó)Python工資布局""制作人:挖掘機(jī)小王子", title_color="#fff", title_pos="left", width=1200, height=600, 
  9. background_color='#404a59'
  10. attr, value = geo.cast(data4) 
  11. geo.add("", attr, value, type="heatmap", is_visualmap=True, visual_range=[0, 300], visual_text_color='#fff'
  12. # 中國(guó)地圖Python工資,此分布是最低薪資 
  13. geo 

關(guān)于作者:

姓名:麥艷濤(原姓貊)

網(wǎng)名:挖掘機(jī)小王子

個(gè)人網(wǎng)站:挖掘機(jī)小王子

責(zé)任編輯:未麗燕 來(lái)源: Python中文社區(qū)
相關(guān)推薦

2020-03-11 14:39:26

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

2017-10-14 13:54:26

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

2022-08-26 09:15:58

Python可視化plotly

2020-10-22 08:52:52

Python數(shù)據(jù)集可視化

2022-02-23 09:50:52

PythonEchartspyecharts

2020-05-26 11:34:46

可視化WordCloud

2017-02-07 15:54:14

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

2017-10-31 09:38:53

大數(shù)據(jù)數(shù)據(jù)可視化Python

2024-08-20 18:16:49

數(shù)據(jù)可視化Python

2018-11-30 10:28:44

Python反爬網(wǎng)頁(yè)

2017-03-28 14:57:23

kylinsuperset可視化

2017-07-12 16:07:49

大數(shù)據(jù)數(shù)據(jù)可視化

2015-08-20 10:00:45

可視化

2018-12-03 16:50:23

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

2017-06-29 11:26:08

Python數(shù)據(jù)可視化

2019-01-21 15:10:11

佩奇可視化數(shù)據(jù)

2021-10-11 08:04:22

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

2020-09-02 13:56:03

Python可視化數(shù)據(jù)

2014-08-19 10:47:11

數(shù)據(jù)可視化大數(shù)據(jù)

2012-04-10 15:31:06

HTML 5
點(diǎn)贊
收藏

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