嗨喽~大家好呀,这里是魔王呐 ❤ ~!
python更多源码/资料/解答/教程等 点击此处跳转文末名片免费获取
一. 数据来源分析
-
明确需求
明确采集网站以及数据内容
数据: 职位信息网址:
https://we.51job.com/pc/search?keyword=python&searchType=3&sortType=0&metro=
-
抓包分析
通过开发者工具进行抓包分析
I. 打开开发者工具: F12 / 右键点击检查选择network
暂时可能没有数据包或者数据包比较少 <数据不完整>
II. 刷新网页: 让数据内容重新加载一遍
III. 通过关键字去搜索查询对应数据包
关键字: 我们需要的数据
https://we.51job.com/api/job/search-pc?api_key=51job×tamp=1690980373&keyword=python&searchType=3&function=&industry=&jobArea=000000&jobArea3=&landmark=&metro=&salary=&workYear=°ree=&companyType=&companySize=&jobType=&issueDate=&sortType=0&pageNum=1&requestId=&pageSize=30&source=1&accountId=&pageCode=sou%7Csou%7Csoulb
二. 代码实现步骤
-
发送请求, 模拟浏览器对于url地址发送请求
请求链接地址: 找到数据包链接
-
获取数据, 获取服务器返回响应数据
开发者工具: response <所有数据内容>
-
解析数据, 提取我们需要的数据内容
职位,公司,薪资,城市,经验,学历要求等
-
保存数据, 把数据保存本地文件 csv Excel 数据库 文本…
职位信息代码实现
请求数据
上面的抓包分析已经说的很清楚,所以不再赘述
这里请求我们需加上
-
Cookie:用户信息, 常用于检测是否登陆账号 <登陆与否都有cookie>
-
Referer:防盗链, 告诉服务器请求链接地址, 是从哪里跳转过来
-
User-Agent:用户代理, 表示浏览器基本身份信息
'''
遇到问题没人解答?小编创建了一个Python学习交流QQ群:926207505
寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!
'''
# 模拟浏览器
headers = {
'Cookie': 'guid=54b7a6c4c43a33111912f2b5ac6699e2; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%2254b7a6c4c43a33111912f2b5ac6699e2%22%2C%22first_id%22%3A%221892b08f9d11c8-09728ce3464dad8-26031d51-3686400-1892b08f9d211e7%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%7D%2C%22identities%22%3A%22eyIkaWRlbnRpdHlfY29va2llX2lkIjoiMTg5MmIwOGY5ZDExYzgtMDk3MjhjZTM0NjRkYWQ4LTI2MDMxZDUxLTM2ODY0MDAtMTg5MmIwOGY5ZDIxMWU3IiwiJGlkZW50aXR5X2xvZ2luX2lkIjoiNTRiN2E2YzRjNDNhMzMxMTE5MTJmMmI1YWM2Njk5ZTIifQ%3D%3D%22%2C%22history_login_id%22%3A%7B%22name%22%3A%22%24identity_login_id%22%2C%22value%22%3A%2254b7a6c4c43a33111912f2b5ac6699e2%22%7D%2C%22%24device_id%22%3A%221892b08f9d11c8-09728ce3464dad8-26031d51-3686400-1892b08f9d211e7%22%7D; nsearch=jobarea%3D%26%7C%26ord_field%3D%26%7C%26recentSearch0%3D%26%7C%26recentSearch1%3D%26%7C%26recentSearch2%3D%26%7C%26recentSearch3%3D%26%7C%26recentSearch4%3D%26%7C%26collapse_expansion%3D; privacy=1690977331; Hm_lvt_1370a11171bd6f2d9b1fe98951541941=1688644162,1690977332; Hm_lpvt_1370a11171bd6f2d9b1fe98951541941=1690979700; search=jobarea%7E%60%7C%21recentSearch0%7E%60000000%A1%FB%A1%FA000000%A1%FB%A1%FA0000%A1%FB%A1%FA00%A1%FB%A1%FA99%A1%FB%A1%FA%A1%FB%A1%FA99%A1%FB%A1%FA99%A1%FB%A1%FA99%A1%FB%A1%FA99%A1%FB%A1%FA9%A1%FB%A1%FA99%A1%FB%A1%FA%A1%FB%A1%FA0%A1%FB%A1%FApython%A1%FB%A1%FA2%A1%FB%A1%FA1%7C%21recentSearch1%7E%60010000%2C020000%2C030200%2C040000%2C090200%A1%FB%A1%FA000000%A1%FB%A1%FA0000%A1%FB%A1%FA00%A1%FB%A1%FA99%A1%FB%A1%FA%A1%FB%A1%FA99%A1%FB%A1%FA99%A1%FB%A1%FA99%A1%FB%A1%FA99%A1%FB%A1%FA9%A1%FB%A1%FA99%A1%FB%A1%FA%A1%FB%A1%FA0%A1%FB%A1%FApython%A1%FB%A1%FA2%A1%FB%A1%FA1%7C%21; acw_tc=ac11000116909815830311339e00e171910033f29edaf40a9eeee0368c9110; acw_sc__v2=64ca54d2e0effb7debcb282d322b72a10e69b3c3; JSESSIONID=C9461FAAB4EEE90D560B795EF5067188; ssxmod_itna2=Yui=DK0I4+xR2xl4iqdRbUwqGqLBxQqKaBxikvTChDlPIQDjbrx0=ntaoC6D60BGQKRCldAQhTtK3g0q52oj02etMgwGTwD1YkKqKVKnCSBO42lue=O7gl1BbsBYS+/0+Vj3n97v/gTOReY8U1nFVQhTh6vQDruNzp9CTtm7DpIQux5r7huQyayh/7pvt9vwvF8zxFizxE3h3RYIKfKm4pid8t4+ehdr4=0Utj0w8Qe5TjLNdUBkR7PFNleEm=nQ7P47z2PkQGqFQdWFCnE=heRRaZYks/7cQQy+DOHdqWUHCBviqy44mhSW9djb/nuRe71K07ibT4b4UuefvBWnQl2L8mGj4LA+gCvzRbg84czpumImzm9/xCtoHQgQCp3qOZ+o6ee=xoFQgqdWlIPtubtP8Gfoi2xty9NygQgR+bpihmbPSyDOjefiKyQZommom0cT5+we8uGTFOgbrLihvWVxNoprgRPxKW3yfY4m9pV/4WGmiPTgIxqqlhYQ5txDKLDtYCIAPYOP0Oe5k2=K3hOTvTG7Ywq0xD7=DY9xeD==; ssxmod_itna=eq0xcDuiD=DQYiIK0Lc7tD9DRE6oiYoYdd77Dl=7QxA5D8D6DQeGTT2deWbiK=eDCqfsYIBdTqapWtY7whq8AmSoDHxY=DUPObIoD4fKGwD0eG+DD4DWDmmFDnxAQDjxGpnXvTs=DEDmb8DWPDYxDrE=KDRxi7DDyd7x07DQH8OGiqEOYF33vm0hGhqQi8D75pDlpxEfEwfR8qBOAAm/53wx0kg40OnoHz8ooDU0IzcZyrdG4eI0qxT7G3YW0KtGiKIQDehmrx7uq4Yj2TxgenHirS4D',
'Referer': 'https://we.51job.com/pc/search?keyword=python&searchType=3&sortType=0&metro=',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36'
}
# 请求链接
url = 'https://we.51job.com/api/job/search-pc'
# 请求参数
data = {
'api_key': '51job',
'timestamp': '1690982356',
'keyword': 'python',
'searchType': '2',
'function': '',
'industry': '',
'jobArea': '000000',
'jobArea2': '',
'landmark': '',
'metro': '',
'salary': '',
'workYear': '',
'degree': '',
'companyType': '',
'companySize': '',
'jobType': '',
'issueDate': '',
'sortType': '0',
'pa