<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Python3爬取前程無憂招聘數(shù)據(jù)教程

          共 898字,需瀏覽 2分鐘

           ·

          2020-09-03 11:10

          文章來自群友 易某某 的投稿,在此表示感謝!
          原文鏈接:https://blog.csdn.net/weixin_42572590/article/details/103443213

          前幾天,我發(fā)表了一篇名為《基于Python|“數(shù)據(jù)分析崗位”招聘情況分析!(此為超鏈接,可以跳轉(zhuǎn))的文章,看到這篇文章的時(shí)候,小伙伴們很是羨慕。

          “我們也想要數(shù)據(jù)集進(jìn)行數(shù)據(jù)處理與分析,最終結(jié)果可視化,但是苦于沒有數(shù)據(jù)集。嚴(yán)小樣兒你的數(shù)據(jù)集能給我一份嗎?

          授人以魚不如授人以漁,今天,嚴(yán)小樣兒直接教大家爬取招聘數(shù)據(jù)集,代碼詳細(xì),粘貼后run一下就出結(jié)果,數(shù)據(jù)集有了,想怎么分析怎么分析。一起來看看吧~

          目錄

          ????1、背景介紹

          2、爬取數(shù)據(jù)保存到txt文件
          (1)網(wǎng)頁分析
          (2)代碼編寫
          (3)最終結(jié)果
          3、爬取數(shù)據(jù)保存到excel文件
          (1)代碼編寫
          (2)最終結(jié)果


          1、背景介紹

          近幾年掀起了一股Python風(fēng),各大網(wǎng)站、公眾號等都在宣傳和力挺Python。我開始挺抗拒的,別人越是這么說,我就偏不這么干。后面…由于畢設(shè)需要使用Python…結(jié)果,嗯!真香!!
          好了,言歸正傳。本文主要爬取前程無憂大數(shù)據(jù)類相關(guān)職位的一些基本信息:崗位名稱、公司名稱、工作地點(diǎn)、薪資以及崗位發(fā)布時(shí)間。對于我們這種新生,爬取這種還是比較有成就感的。

          2、爬取數(shù)據(jù)保存到txt文件

          (1)網(wǎng)頁分析
          進(jìn)入前程無憂招聘網(wǎng)站,搜索大數(shù)據(jù),就會出現(xiàn)如下圖1所示:
          圖1 前程無憂數(shù)據(jù)類招聘頁面
          我們進(jìn)入到這個(gè)網(wǎng)站后,需要關(guān)注兩個(gè)地方,一是觀察此網(wǎng)頁的網(wǎng)址,二是查看此網(wǎng)頁的源碼。具體見下圖2和圖3:

          圖2 網(wǎng)址分析
          根據(jù)圖2我們可以分析出:前程無憂分頁的規(guī)律,我們分頁爬取只要修改這里的數(shù)字即可!

          圖3 源代碼分析
          根據(jù)圖3我們可以分析出要想爬取我們想要的數(shù)據(jù),就要分析這些數(shù)據(jù)在網(wǎng)頁里面的規(guī)律,以此來寫出正則表達(dá)式。
          根據(jù)圖3我們可以寫出其正則表達(dá)式為:
          1?pat='(.*?).*?(.*?).*?(.*?)'
          (2)代碼編寫
          通過前面的網(wǎng)頁分析,我們已經(jīng)發(fā)現(xiàn)網(wǎng)址規(guī)律,已經(jīng)發(fā)現(xiàn)正則表達(dá)式規(guī)律。下面,我們就可以開始書寫代碼爬取數(shù)據(jù)啦!
          1#爬取前程無憂Python數(shù)據(jù)--寫進(jìn).txt文件
          2import?urllib.request
          3import?re
          4
          5#獲取源碼
          6def?get_content(page):
          7????url='https://search.51job.com/list/000000,000000,0000,00,9,99,%25E5%25A4%25A7%25E6%2595%25B0%25E6%258D%25AE,2,'+str(page)+'.html?lang=c&postchannel=0000&workyear=99&cotype=99°reefrom=99&jobterm=99&companysize=99&ord_field=0&dibiaoid=0&line=&welfare='
          8????html?=?urllib.request.urlopen(url).read().decode("GBK","ignore")#打開網(wǎng)址
          9????return?html
          10
          11
          12#讀取此網(wǎng)頁里面的內(nèi)容并把正則表達(dá)式匹配的數(shù)據(jù)提取出來
          13def?get(html):
          14????pat='(.*?).*?(.*?).*?(.*?)'
          15????#pat='
          16????rst=re.compile(pat,re.S).findall(html)
          17????return?rst
          18
          19
          20#多頁處理,下載到文件
          21for?i?in?range(1,10):
          22????print("正在爬取第"+str(i)+"頁數(shù)據(jù)...")
          23????html=get_content(i)#調(diào)用獲取網(wǎng)頁源碼
          24????#print("網(wǎng)址源碼:"+html)
          25????rst=get(html)
          26????#print("數(shù)據(jù):"+str(rst))
          27????for?j?in?rst:
          28????????with?open("D:/Test/data/data1.txt","a",encoding="utf-8")?as?f:
          29????????????f.write(j[0]+'\t'+j[1]+'\t'+j[2]+'\t'+j[3]+'\t'+j[4]+'\t'+'\n')
          30????????????f.close()
          31print('程序運(yùn)行結(jié)束!')
          (3)最終結(jié)果


          3、爬取數(shù)據(jù)保存到excel文件

          前面的分析都是一模一樣,唯一不同的就是代碼有點(diǎn)區(qū)別!
          (1)代碼編寫
          1#爬取前程無憂Python數(shù)據(jù)--創(chuàng)建并寫進(jìn)excel文件
          2import?urllib.request
          3import?re
          4import?xlwt?#用來創(chuàng)建excel文檔并寫入數(shù)據(jù)
          5
          6#獲取源碼
          7def?get_content(page):
          8????url='https://search.51job.com/list/000000,000000,0000,00,9,99,%25E5%25A4%25A7%25E6%2595%25B0%25E6%258D%25AE,2,'+str(page)+'.html?lang=c&postchannel=0000&workyear=99&cotype=99°reefrom=99&jobterm=99&companysize=99&ord_field=0&dibiaoid=0&line=&welfare='
          9????html?=?urllib.request.urlopen(url).read().decode("GBK","ignore")#打開網(wǎng)址
          10????return?html
          11
          12#讀取此網(wǎng)頁里面的內(nèi)容并把正則表達(dá)式匹配的數(shù)據(jù)提取出來
          13def?get(html):
          14????pat='(.*?).*?(.*?).*?(.*?)'
          15????rst=re.compile(pat,re.S).findall(html)
          16????return?rst
          17
          18#爬取到的內(nèi)容寫入excel表格
          19def?excel_write(rst,index):
          20????for?item?in?rst:
          21????????for?i?in?range(0,5):
          22????????????ws.write(index,i,item[i])?#行,列,數(shù)據(jù)
          23????????print(index)
          24????????index?+=?1
          25
          26newTable="D:/Test/data/data1.xls"?#表格名字
          27wb?=?xlwt.Workbook(encoding='utf-8')????#創(chuàng)建excel文件,聲明編碼
          28ws?=?wb.add_sheet('sheet1')?#創(chuàng)建表格
          29headData?=?['招聘職位','公司','地址','薪資','日期']?#表頭信息
          30for?colnum?in?range(0,5):
          31????ws.write(0,colnum,headData[colnum],xlwt.easyxf('font:bold?on'))?#行,列
          32
          33for?each?in?range(1,10):
          34????index?=?(each-1)?*?50?+?1
          35????excel_write(get(get_content(each)),index)
          36wb.save(newTable)
          37print('程序運(yùn)行結(jié)束!')
          (2)最終結(jié)果


          看到這兒,很多小伙伴會說,數(shù)據(jù)集有了,可是不知道怎么分析啊?!嚴(yán)小樣兒貼心地告訴你兩種方法:


          1. 查看頭條文章,內(nèi)有Excel+Tableau教程;

          2. 鏈接送上,傳送門祝你成功。

          傳送門1:基于Python|“數(shù)據(jù)分析崗位”招聘情況分析!

          傳送門2:日常答疑|Python向量化操作、矩陣運(yùn)算

          傳送門3:分組排序求前三?TopN問題?一文教你MySQL各類排序操作


          --END--



          (掃碼關(guān)注我,帶你玩轉(zhuǎn)數(shù)據(jù)分析)


          讀完、看完,點(diǎn)在看~

          瀏覽 61
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評論
          圖片
          表情
          推薦
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  日本操B电影 | 奇米影视四色中文字幕 | 亚洲AV无码秘 蜜桃永瀬ゆい | 欧美日韩中文在线视频 | 亚州视频一区 |