欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

R語言爬蟲如何爬取招聘網(wǎng)站的招聘信息

R語言爬蟲如何爬取招聘網(wǎng)站的招聘信息,針對(duì)這個(gè)問題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問題的小伙伴找到更簡(jiǎn)單易行的方法。

站在用戶的角度思考問題,與客戶深入溝通,找到周村網(wǎng)站設(shè)計(jì)與周村網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都網(wǎng)站制作、成都做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、空間域名、雅安服務(wù)器托管、企業(yè)郵箱。業(yè)務(wù)覆蓋周村地區(qū)。

R語言爬取招聘網(wǎng)上的招聘信息,雖然R做爬蟲確實(shí)沒python專業(yè),但是有一個(gè)包rvest我覺得還不錯(cuò),我嘗試爬取58同城招聘網(wǎng)上的數(shù)據(jù)。

rvest包,用到的函數(shù)有:

read_html(),

html_nodes(),

html_text(),

html_attr();

具體源代碼如下:

#####加載相關(guān)包############

library(xml2)

library(rvest)

library(base)

下面獲得每個(gè)子網(wǎng)站的地址

#58同城主網(wǎng)站網(wǎng)址

url<-"http://jingzhou.58.com/?utm_source=market&spm=b-31580022738699-pe-f-829.hao360_101"

web<-read_html(url,encoding = "utf-8")

xpath<-"div.col3 a"

#############子網(wǎng)站網(wǎng)址###########

title<-web%>%html_nodes(xpath)%>%html_text()

link<-web%>%html_nodes(xpath)%>%html_attr("href")

##########對(duì)子網(wǎng)站翻頁########

id<-c(1:20)

pn<-paste0("pn",id,"/")#下載的網(wǎng)址有規(guī)律地缺失paste0()是字符串連接函數(shù)

###########清理網(wǎng)址中的缺失值#########

for (http in 1:length(link)) {

  httplink<-substr(link[http],1,4)

  if(httplink=="http"){link[http]<-substr(link[http],"",link[http])}

}

link<-na.omit(link)

filename<-"E:\\工作簿1.csv"#本地文件路徑,用以存儲(chǔ)下載的數(shù)據(jù)

job<-"職位";company<-"公司";location<-"地域";time<-"發(fā)布時(shí)間"

data<-data.frame(job,company,location,time)

len<-max(length(job),length(company),length(location),length(time))

########從子網(wǎng)站爬取數(shù)據(jù)##########

for (i in 1:length(link)) {

  link0<-paste0("http://jingzhou.58.com",link[i],pn,"&utm_source=market&spm=b-31580022738699-pe-f-829.hao360_101&PGTID=0d100000-00d9-7474-25a7-e93482a12861&ClickID=xxxx")

  link1<-paste0("http://jingzhou.58.com",link[i],pn,"?utm_source=market&spm=b-31580022738699-pe-f-829.hao360_101&PGTID=0d100000-00d9-7fce-21b0-b8956617e76f&ClickID=xxxx")

#####網(wǎng)址最后的變化###########

   for (j in 1:length(link)) {

    link0<-gsub("xxxx",j,link0)

    link1<-gsub("xxxx",j,link1)

#####網(wǎng)站名的兩種類型用trycatch()消除錯(cuò)誤#####

    for (k in 1:length(pn)) {

    tryCatch(

      {web<-read_html(link0[k],encoding = "utf-8")},

      error={web<-read_html(link1[k],encoding = "utf-8")})

###########提取需要的變量###########

  job_path<-"dt a"; #獲取職位節(jié)點(diǎn)

  company_path<-"dd.w271 a";#獲取公司節(jié)點(diǎn)

  location_path<-"dd.w96";#獲取地域節(jié)點(diǎn)

  time_path<-"dd.w68";#獲取發(fā)布時(shí)間節(jié)點(diǎn)

  job<-web%>%html_nodes(job_path)%>%html_text();

  company<-na.omit(web%>%html_nodes(company_path)%>%html_text());

  location<-web%>%html_nodes(location_path)%>%html_text();

  time<-web%>%html_nodes(time_path)%>%html_text();

  job<-job[1:len];company<-company[1:len];location<-location[1:len];time<-time[1:len]#長(zhǎng)度一致#

  data1<-data.frame(job,company,location,time);

 if(length(data>0)){

  data<-na.omit(rbind(data,data1))}

  else

  {data1<-rep(NA,len);data<-na.omit(rbind(data,data1))}

    }

  }

  Sys.sleep(3)#每隔3秒鐘停一次,防止反爬蟲

  print(i)

  print("sleep end,download start!")

}

data<-data[-1,]

write.csv(data,file = filename)

就是這樣了,自己實(shí)操一遍才好。

關(guān)于R語言爬蟲如何爬取招聘網(wǎng)站的招聘信息問題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識(shí)。

文章標(biāo)題:R語言爬蟲如何爬取招聘網(wǎng)站的招聘信息
文章地址:http://chinadenli.net/article20/ggpojo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)公司建站公司軟件開發(fā)移動(dòng)網(wǎng)站建設(shè)企業(yè)網(wǎng)站制作網(wǎng)站維護(hù)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

綿陽服務(wù)器托管