1. 程式人生 > 程式設計 >python爬蟲判斷招聘資訊是否存在的例項程式碼

python爬蟲判斷招聘資訊是否存在的例項程式碼

在找工作的時候,我們會選擇上網查詢招聘的資訊,或者是通過一些招聘會進行現場面試。但由於資訊更新不及時,有一些崗位會出現下架的情況,如果我們不注意的話,可能就撲了空。在時間上耽誤了不說,面試的資訊也會受到一點點打擊。今天小編就教大家python爬蟲來判斷招聘資訊是否存在。

首先這裡需要一個判斷某條招聘是否還掛在網站上的方法,這個暫時想到了還沒弄,然後對於釋出時間在兩個月之前的資料,就不進行統計計算。

以下是完成程式碼:

{
  "_id" : ObjectId("5a30ad2068504386f47d9a4b"),"city" : "蘇州","companyShortName" : "藍海彤翔","companySize" : "100-499人","education" : "本科","financeStage" : "B輪","industryField" : "網際網路","level" : 3,"pid" : "11889834","positionLables" : [
    "PHP","ThinkPHP"
  ],"positionName" : "php研發工程師","salary" : {
    "avg" : 7500.0,"low" : 7000,"high" : 8000
  },"time" : "2017-06-06","updated_at" : "2017-12-13 18:31:15","workYear" : "1-3年","detail" : "1、處理landcloud雲端計算相關係統的各類開發和調研工作;2、處理coms高效能運算的各類開發和調研工作崗位要求:1、本科學歷,兩年以上工作經驗,熟悉PHP開發,瞭解常用的php開發技巧和框架;2、瞭解C++,python及Java開發;3、有一定的研發能力和鑽研精神;4、有主動溝通能力和吃苦耐勞的精神。","location" : "蘇州市高新區科技城錦峰路158號101park8幢"

例項擴充套件:

python爬蟲爬取騰訊招聘資訊 (靜態爬蟲)

import requests
from bs4 import BeautifulSoup
from math import ceil

header = {
  'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/67.0.3396.99 Safari/537.36'}


# 獲取崗位頁數
def getJobPage(url):
  ret = requests.get(url,headers=header)
  ret.encoding = "utf-8" # 解決亂碼問題
  html = ret.text
  soup = BeautifulSoup(html,'html.parser')
  # 獲取崗位總數,< span class ="lightblue total" > 512 < / span >
  totalJob = soup.select('span[class="lightblue total"]')[0].text
  jobPage = ceil(int(totalJob) / 10)
  return jobPage


def getJobOrder(url):
  ret = requests.get(url,'html.parser')
  # 工作職責
  jobRequests = soup.select('ul[class="squareli"]')[0].text
  # 工作要求
  jobOrder = soup.select('ul[class="squareli"]')[1].text
  return jobRequests,jobOrder


# 獲取崗位資訊
def getJobInfo(url):
  myfile = open("tencent_job.txt","a",encoding='gb18030',errors='ignore') # 解決亂碼問題
  ret = requests.get(url,'html.parser')
  jobList = soup.find_all('tr',class_=['even','odd'])
  for job in jobList:
    # url
    jobUrl = "https://hr.tencent.com/" + job.select('td:nth-of-type(1) > a')[0]['href']
    # 職位名稱
    jobName = job.select('td:nth-of-type(1) > a')[0].text
    # 人數
    jobPeople = job.select('td:nth-of-type(3)')[0].text
    # 地點
    jobAddre = job.select('td:nth-of-type(4)')[0].text
    # 釋出時間
    jobTime = job.select('td:nth-of-type(5)')[0].text
    # 工作職責
    jobRequests = getJobOrder(jobUrl)[0]
    # 工作要求
    jobOrder = getJobOrder(jobUrl)[1]

    #print(jobName,jobUrl,jobAddre,jobPeople,jobTime,jobRequests,jobOrder)

    tt = jobName + " " + jobUrl + " " + jobAddre + " " + jobPeople + " " + jobTime + " " + jobRequests + " " + jobOrder
    myfile.write(tt + "\n")


if __name__ == '__main__':
  mainurl = 'https://hr.tencent.com/position.php?keywords=python'
  jobPage = getJobPage(mainurl)
  print(jobPage)
  for page in range(jobPage):
    pageUrl = 'https://hr.tencent.com/position.php?keywords=python&start=' + str(page * 10) + '#a'
    print("第" + str(page + 1) + "頁")
    getJobInfo(pageUrl)

到此這篇關於python爬蟲判斷招聘資訊是否存在的例項程式碼的文章就介紹到這了,更多相關python判斷招聘資訊的存在內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!