美文网首页
基于rvest包爬取BOSS直聘-上海里有关“数据分析”的职位信

基于rvest包爬取BOSS直聘-上海里有关“数据分析”的职位信

作者: 小T数据站 | 来源:发表于2018-12-10 15:34 被阅读15次

    目前一心想入门数据分析岗位的我,很好奇目前数据分析岗位的现状,故而准备爬取Boss直聘里上海目前数据分析岗位的情况。
    先上源代码:

    library(xml2)
    library(rvest)
    library(stringr)
    library(dplyr)
    i <- 1:10
    job_inf <- data.frame()
    for (i in 1:10){
      webpage <- read_html(str_c("https://www.zhipin.com/c101020100/h_101020100/?query=%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90&page=",i,"&ka=page-",i),encoding="UTF-8")
      job_title_html <- html_nodes(webpage,".job-title")
      job_title <- html_text(job_title_html)
      salary_html <- html_nodes(webpage,".red")
      salary <- html_text(salary_html)
      company_basic_html <- html_nodes(webpage,".company-text p")
      company_basic <- gsub("<p>","",company_basic_html)
      company_basic <- gsub("em class=\"vline\"></em>","",company_basic)
      company_basic <- gsub("</p>","",company_basic)
      company_basic <- as.character(company_basic)
      job_needs_html <- html_nodes(webpage,".info-primary p")
      job_needs <- gsub("<p>","",job_needs_html)
      job_needs <- gsub("em class=\"vline\"></em>","",job_needs)
      job_needs <- gsub("</p>","",job_needs)
      job_needs <- str_replace_all(job_needs," ","")
      job_needs <- as.character(job_needs)
      job <- data.frame(job_title,salary,company_basic,job_needs)
      job_inf <- rbind(job_inf,job)
    }
    write.csv(job_inf,file="bossdata.csv")
    

    以上代码若有不解之处,可参考R言rvest包爬取南京二手房信息里的相关解释。
    得到初始如下:

    初始数据
    通过Excel整理如下:
    初步处理
    在利用tableau软件进行可视化呈现如下:
    图1
    图2
    以上就是正文的全部了,如有不尽之处还请各位看官不吝赐教~

    链接:源代码 密码:13ye

    链接:tableau文件 密码:xz0j

    相关文章

      网友评论

          本文标题:基于rvest包爬取BOSS直聘-上海里有关“数据分析”的职位信

          本文链接:https://www.haomeiwen.com/subject/xrzrhqtx.html