爬取的url:https://www.lagou.com/jobs/list_python?labelWords=&fromSearch=true&suginput=
爬取職位名稱,薪水,公司,待遇這些
抓包,找到信息加載為一個post請求返回
查看他攜帶的數據,里面是關鍵字(python)和頁數(pn),這個sid每次都會改變,經測試,該post請求主要檢查的是cookies,這個sid不需要(一次一次試出來的)
既然需要攜帶cookie,那我們首先建立一個session連接,獲得cookie
1 s.get(url, headers=headers, timeout=3) 2 cookie = s.cookies
之后我們再用這個cookie構造post請求
1 response = s.post(url2, data=data, headers=headers, cookies=cookie) 2 html = response.text
成功返回json數據,之后解析json取出我們需要的數據就可以了
1 json_data = json.loads(html) 2 resulet = json_data['content']['positionResult']['result'] 3 for datas in resulet: 4 positionName = datas['positionName'] 5 companyShortName = datas['companyShortName'] 6 companySize = datas['companySize'] 7 salary = datas['salary'] 8 workYear = datas['workYear'] 9 positionAdvantage = datas['positionAdvantage'] 10 city = datas['city'] 11 firstType = datas['firstType'] 12 secondType = datas['secondType']
最后將數據寫入excel
取出薪水和公司名稱做一個簡單的可視化
可以看到成都的python崗位平均薪資12 - 20k
最低工資2k,最高工資60k
在20 - 30k工資的人數占比最高為30%,0-10k的人數占比還是挺低的,當然都有學歷和工作經驗的要求(我就懶得分析了)