進入智聯招聘官網,在搜索界面輸入‘數據分析師',界面跳轉,按F12查看網頁源碼,點擊network
?選中XHR,然后刷新網頁
可以看到一些Ajax請求, 找到畫紅線的XHR文件,點擊可以看到網頁的一些信息
在Header中有Request URL,我們需要通過找尋Request URL的特點來構造這個請求網址,
點擊Preview,可以看到我們所需要的信息就存在result中,這信息基本是json格式,有些是列表;
下面我們通過Python爬蟲來爬取上面的信息;
代碼如下:
import requests from urllib.parse import urlencode import json #from requests import codes #import os #from hashlib import md5 #from multiprocessing.pool import Pool #import re def get_page(offset): params = { 'start': offset, 'pageSize': '90', 'cityId': '530', 'salary': '0,0', 'workExperience': '-1', 'education': '-1', 'companyType': '-1', 'employmentType': '-1', 'jobWelfareTag': '-1', 'kw': '數據分析師', 'kt': '3', '_v': '0.77091902', 'x-zp-page-request-id': '8ff0aa73bf834b408f46324e44d89b84-1562722989022-210101', 'x-zp-client-id': '2dc4c9a4-e80d-4488-84a3-03426dd69a1e' } base_url = 'https://fe-api.zhaopin.com/c/i/sou?' url = base_url + urlencode(params) try: resp = requests.get(url) print(url) if 200 == resp.status_code: print(resp.json()) return resp.json() except requests.ConnectionError: return None def get_information(json_page): if json_page.get('data'): results = json_page.get('data').get('results') for result in results: yield { 'city': result.get('city').get('display'), 'company': result.get('company').get('name'), #'welfare':result.get('welfare'), 'workingExp':result.get('workingExp').get('name'), 'salary':result.get('salary'), 'eduLevel':result.get('eduLevel').get('name') } print('succ') def write_to_file(content): with open('result.txt','a',encoding='utf-8') as f: print(type(json.dumps(content))) f.write(json.dumps(content,ensure_ascii=False)+'\n') def main(offset): json_page=get_page(offset) for content in get_information(json_page): write_to_file(content) if __name__=='__main__': for i in range(10): main(offset=90*i)
爬取結果如下:
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
