Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 国产成人精品日本亚洲专区6,先锋影音一区二区,91免费国产视频

          整合營銷服務(wù)商

          電腦端+手機(jī)端+微信端=數(shù)據(jù)同步管理

          免費咨詢熱線:

          實習(xí)僧招聘網(wǎng)爬蟲數(shù)據(jù)可視化

          實習(xí)僧招聘網(wǎng)爬蟲數(shù)據(jù)可視化


          本來對實習(xí)僧網(wǎng)站是沒什么好感的,因為之前自己在實習(xí)僧上投的實習(xí)簡歷幾乎全部都石沉大海了(一個文科生偏要去投數(shù)據(jù)分析崗不碰壁才怪~_~)!

          然鵝看到最近知乎爬蟲圈兒里的兩大趨勢:爬美圖;爬招聘網(wǎng)站。

          后來大致了解下了,幾乎各類大型的招聘文章都被別人爬過了,自己再去寫免不了模仿之嫌,而且大神們都是用Python去爬的(Python我剛學(xué)會裝包和導(dǎo)數(shù)據(jù)),自己也學(xué)不來。

          現(xiàn)在只能選一個還沒怎么被盯上的招聘網(wǎng)站,沒錯就它了——實習(xí)僧。

          說老實話,實習(xí)僧的網(wǎng)站做的還是不錯的,看著結(jié)構(gòu)挺簡單,可是我用比較主流的Rvest和RCurl都失敗了(主要自己技術(shù)太渣了,抓包又抓不好)。最后只能勉強(qiáng)用RSelenium爬完了全部所需內(nèi)容。(用代碼驅(qū)動瀏覽器的好處就是不用怎么考慮時延和偽裝包頭了,但是要遍歷成百上千頁網(wǎng)址真的很耗時,爬完這個數(shù)據(jù)用了大約40多分鐘)。

          以下是爬蟲部分:

          library(rvest)

          library(stringr)

          library(plyr)

          library(dplyr)

          library(Rwebdriver)

          library(dplyr)

          library(Rwordseg)

          library(wordcloud2)

          library(treemap)

          library(showtext)

          library(Cairo)

          library(ggplot2)

          library(scales)

          library(grid)

          library(RColorBrewer)

          library(ggimage)

          library(geojsonio)

          本文主要用的Rwebdriver包來驅(qū)動Chrome瀏覽器,使用該包需要提前配置好桌面環(huán)境:

          • 下載selenium啟動服務(wù)器;

          • 下載Chrome的chromedriver插件并放入Chrome主目錄(添加系統(tǒng)環(huán)境變量)

          • 下載Rwebdriver包

          在cmd或者powershell中啟動Selenium服務(wù)器:

          options(stringsAsFactors=FALSE,warn=FALSE)

          cd "D:/Rwebdriver-master"

          java -jar selenium-server-standalone-3.3.1.jar

          在Rsudio中新建進(jìn)程:

          start_session(root="http://localhost:4444/wd/hub/",browser="chrome")

          遍歷實習(xí)僧的招聘信息網(wǎng)頁

          baseurl<-"http://www.shixiseng.com/interns?k=&t=zh&c=%E5%85%A8%E5%9B%BD&p="

          pageurl<-paste0(baseurl,1:500)

          本文所用到的爬蟲代碼部分:

          homepage=internship=companyweb=company=Position=address=salary=period=duration=NULL

          fun<-function(url){

          post.url(url=url)

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

          homepage <-baseinfo%>%html_nodes("div.po-name>div.names>a")%>% html_attr("href")

          internship<-baseinfo%>%html_nodes("div.po-name>div.names>a")%>%html_text()

          companyweb<-baseinfo%>%html_nodes("div.po-name>div.part>a")%>%html_attr("href")

          company <-baseinfo%>%html_nodes("div.po-name>div.part>a")%>%

          html_text()

          Position <-baseinfo%>%html_nodes("div.po-name>div.part")%>%

          html_text()

          address <-baseinfo%>%html_nodes("div.po-detail>div.addr>span")%>%

          html_text()

          salary <-baseinfo%>%html_nodes("div.po-detail>div.xz>span:nth-child(2)")%>%

          html_text()

          period <-baseinfo%>%html_nodes("div.po-detail>div.xz>span:nth-child(5)")%>%

          html_text()

          duration <-baseinfo%>%html_nodes("div.po-detail>div.xz>span:nth-child(8)")%>%

          html_text()

          interninfo<-data.frame(homepage,internship,companyweb,company,Position,address,salary,period,duration)

          }

          用一個循環(huán)執(zhí)行上述程序:

          final<-data.frame()

          for (i in pageurl){

          final<-rbind(final,fun(i))

          }

          quit_session()

          DT::datatable(final)

          保存本地:

          write.table (final,"D:/R/File/shixiseng.csv",sep=",",row.names=FALSE)

          ##############################################

          接下來做數(shù)據(jù)清洗:

          mydata<-read.csv("D:/R/File/shixiseng.csv",stringsAsFactors=FALSE,check.names=FALSE)

          mydata<-mydata[-5001,]

          #補(bǔ)全實習(xí)發(fā)布單位的招聘信息主頁:

          mydata$homepage<-str_c("http://www.shixiseng.com",mydata$homepage,sep="")

          #補(bǔ)全實習(xí)發(fā)布單位的公司信息主頁:

          mydata$companyweb<-str_c("http://www.shixiseng.com",mydata$companyweb,sep="")

          mydata$work<-str_split(mydata$Position[1:10], " - ", simplify=TRUE)[,2]

          #清除salary中的空格和斜杠

          mydata$salary<-str_trim(mydata$salary,side="both")

          mydata$salary<-str_extract(mydata$salary,"\d+\-\d+")

          #拆分實習(xí)工資的高低區(qū)間

          mydata$salary_low<-str_split(mydata$salary, "-", simplify=TRUE)[,1]

          mydata$salary_high<-str_split(mydata$salary, "-", simplify=TRUE)[,2]

          #清除period中的漢字和特殊字符

          mydata$period<-str_extract(mydata$period,"\d+")

          #清除duration中的漢字和特殊字符

          mydata$duration<-str_extract(mydata$duration,"\d+")

          mydata <- tbl_df(mydata)

          mydata<-select(mydata,-Position)

          #因為address中所含的地址可能有存在多個,影響我們后續(xù)的可視化分析,這里為了方便起見,一律使用第一個地址。

          mydata$address_unique<-str_split(mydata$address, ",", simplify=TRUE)[,1]

          至此,數(shù)據(jù)清洗工作告一段落,接下來我們要進(jìn)入分析與可視化階段

          names(mydata)

          "homepage"-------公司實習(xí)職位簡介

          "internship"-----公司招聘性質(zhì)

          "companyweb"-----公司主頁

          "company"--------公司名稱

          "address"--------所在地

          "address_unique"-所在地(唯一值,只取默認(rèn)第一個地址)

          "salary"---------實習(xí)工資區(qū)間

          "salary_low"-----實習(xí)工資(最低值)

          "salary_high"----實習(xí)工資(最高值)

          "period"---------到崗天數(shù)(每周)

          "duration"-------實習(xí)周期(按月算)

          "work"-----------具體職位

          我們最終獲取的清洗后數(shù)據(jù)如上所示。

          假如本次項目需求(虛擬)要求我們獲取以下幾個問題:

          1、實習(xí)僧的實習(xí)招聘主頁崗位主要是什么性質(zhì)的?

          2、哪些公司最缺實習(xí)僧?

          3、實習(xí)崗位具體分布的地域和城市?

          4、哪些城市對實習(xí)僧的需要最為強(qiáng)烈?

          5、實習(xí)工資大致什么水平,與城市和地域是否有關(guān)系?

          6、實習(xí)崗位一般都要求每周到崗多少天?

          7、實習(xí)周期一般需要多長時間?

          8、哪些職位需求最為頻繁,職位需要量與城市之間的大致是如何分布的?

          帶著這些個問題,讓我們盡情的暢游在可視化的世界里吧……

          1、實習(xí)僧的實習(xí)招聘主頁主要是什么性質(zhì)的?

          length(unique(mydata$internship))

          3357

          絕望了,一共爬了5000條實習(xí)職位信息,做了去重處理,顯示仍有3357條,建議實習(xí)僧的產(chǎn)品運營團(tuán)隊考慮下要不要標(biāo)準(zhǔn)化一下這個職位性質(zhì),內(nèi)門怎么可以創(chuàng)造這么多獨特的職位~_~

          對于這個問題,真的難倒我了,因為所爬數(shù)據(jù)中的職位性質(zhì)沒有統(tǒng)一的預(yù)設(shè)標(biāo)準(zhǔn),所以我只能用文本分詞的形式來進(jìn)行提取了,先分詞,然后統(tǒng)計高頻詞,最后按照詞頻來進(jìn)行模糊分析啦(可我我對文本挖掘一竅不通啊~_~)

          top100<-table(mydata$internship)%>%as.data.frame(stringsAsFactors=FALSE)%>% arrange(desc(Freq))%>%.[1:100,]

          treemap(top100, index=c("Var1"), vSize="Freq",title='實習(xí)僧職位性質(zhì)分布圖',palette='RdBu',

          fontsize.title=18,fontsize.labels=12,fontface.labels="plain",fontfamily.title="mono",fontfamily.labels="mono")

          從實習(xí)職位分布圖上來看,人力資源實習(xí)生職位需求最為強(qiáng)烈,其次是運營、財務(wù)、新媒體,這些類型的職位多為現(xiàn)代新興服務(wù)業(yè),更為符合大學(xué)生這一群體的口味和興趣。

          myrevieww<-mydata$internship

          thewords <- segmentCN(myrevieww,nature=T)%>%unlist()

          thewords <- gsub("[a-z]|\.", "", thewords)

          thewords<-thewords[nchar(thewords)>1]

          reviewdata<-table(thewords)%>%as.data.frame(stringsAsFactors=FALSE)%>% arrange(desc(Freq))%>%filter(thewords!="實習(xí)生")

          wordcloud<-wordcloud2(reviewdata[1:1000,],color="random-light",minSize=.6,size=1,backgroundColor="dark",minRotation=-pi/6,maxRotation=-pi/6,fontFamily="微軟雅黑");wordcloud

          但是將職位性質(zhì)分詞整理成關(guān)鍵詞后,似乎結(jié)果有所不同。

          2、哪些公司最缺實習(xí)僧?

          這里我們來統(tǒng)計所爬職位信息中公司發(fā)布職位的頻率,發(fā)布最多的則作為評價公司對實習(xí)生需求的標(biāo)準(zhǔn)。

          myjob<-table(mydata$company)%>%as.data.frame(stringsAsFactors=FALSE)%>%arrange(desc(Freq))

          #看看前十名都是那些公司:

          myjob15<-arrange(myjob[1:15,],desc(Freq))

          CairoPNG(file="E:/微信公眾號/公眾號——數(shù)據(jù)小魔方/2017年5月/20170512/circle-rose.png",width=1580,height=950)

          showtext.begin()

          ggplot(data=myjob15,aes(x=reorder(Var1,-Freq),y=Freq,fill=Freq))+

          geom_linerange(aes(ymin=0,ymax=42),linetype=5,size=.2,colour="#858585")+

          geom_image(aes(x=0,y=-40),image="D:/R/Image/image1.jpg", size=.2)+

          geom_text(aes(y=45,label=paste0(Var1,"\n",Freq)),vjust=1,size=5)+

          geom_bar(stat="identity",width=1,col="white")+

          geom_hline(yintercept=54,color="black",size=.5)+

          geom_point(aes(y=48,size=Freq),shape=21,fill="#ED7D31",,alpha=0.6,col="orange")+

          labs(title="Top 15 of Company",caption="Data Source:shixiseng")+

          coord_polar(theta="x")+

          ylim(-40,60)+

          scale_size_area(max_size=20)+

          guides(fill=FALSE,size=guide_legend(reverse=TRUE,title=NULL))+

          theme_minimal()+

          theme(

          axis.title=element_blank(),

          axis.text=element_blank(),

          panel.grid=element_blank(),

          legend.text=element_text(family="myfont",size=12),

          legend.title=element_text(family="myfont",size=15,hjust=1),

          plot.title=element_text(family="myfont",size=35),

          plot.caption=element_text(family="myfont",size=18,hjust=0,lineheight=1.2)

          )

          showtext.end()

          dev.off()

          write.table (myjob[1:100,],"D:/R/File/shixiseng_job.csv",sep=",",row.names=FALSE)

          前一百個實習(xí)生需求最旺盛企業(yè):

          3、實習(xí)崗位具體分布的地域和城市?

          先做一個地域分布圖:

          add<-table(mydata$address_unique)%>%as.data.frame(stringsAsFactors=FALSE)%>%arrange(desc(Freq))%>%filter(nchar(Var1)==2)

          #城市經(jīng)緯度查詢:

          library(rjson)

          library(RCurl)

          library(REmap)

          library(baidumap)

          address<-add$Var1

          baidu_lng <- c()

          baidu_lat <- c()

          ak<-"X8zlxPUdSe2weshrZ1WqnWxb43cfBI2N"

          for(location in address){

          url<-paste("http://api.map.baidu.com/geocoder/v2/?ak=",ak,"&callback=renderOption&output=json&address=",location,sep="")

          url_string <- URLencode(url)

          msg.load <- tryCatch({

          json <-readLines(url_string,warn=F,encoding="UTF-8")

          msg.load <- "TRUE"

          },error=function(e) {

          "error"

          }

          )

          if(msg.load=='error'){

          Sys.sleep(runif(1,3,10))

          msg.load <- tryCatch({

          connect <- readLines(url_string,warn=F,encoding="UTF-8")

          msg.load <- "TRUE"

          }, error=function(e){

          "error"

          }

          )

          }

          geo <- fromJSON(substr(json,regexpr("\(",json)+1,nchar(json)-1))

          if(msg.load=='error'){

          lng<-'error1'

          lat<-'error1'

          }else{

          lng<-geo$result$location$lng

          lat<-geo$result$location$lat

          if(length(lng)==0){

          lng <- "error2"

          lat <- "error2"

          }

          }

          lng<-geo$result$location$lng

          lat<-geo$result$location$lat

          baidu_lng<-c(baidu_lng,lng)

          baidu_lat<-c(baidu_lat,lat)

          }

          result<-data.frame(address=address,long=baidu_lng,lat=baidu_lat,stringsAsFactors=FALSE)

          pointdata<-left_join(add,result,by=c("Var1"="address"))

          #成功獲取目標(biāo)城市經(jīng)緯度信息:

          解析來制作分布圖:

          geojson <-readOGR("D:/R/mapdata/State/china.geojson","OGRGeoJSON",stringsAsFactors=FALSE)

          Encoding(geojson$name)<-"UTF-8"

          china_Mapdata<-geojson@data

          china_MapdataPloygon<-fortify(geojson)

          CairoPNG(file="E:/微信公眾號/公眾號——數(shù)據(jù)小魔方/2017年5月/20170512/shixiseng_jobcity.png",width=1200,height=640)

          showtext.begin()

          ggplot()+

          geom_polygon(data=china_MapdataPloygon,aes(x=long,y=lat,group=group),col="grey60",fill="white",size=.2,alpha=.4)+

          geom_point(data=pointdata,aes(x=long,y=lat,size=Freq),shape=21,fill="#C72E29",col="#014D64",alpha=0.6)+

          scale_size_area(max_size=15,guide=guide_legend(reverse=TRUE,title=NULL))+

          coord_map("polyconic") +

          labs(title="實習(xí)僧職位需求城市分布圖",caption="數(shù)據(jù)來源:實習(xí)僧官網(wǎng)")+

          theme(

          title=element_text(family="myfont",size=18),

          plot.title=element_text(size=24),

          plot.caption=element_text(family="myfont",size=18,hjust=0),

          panel.grid=element_blank(),

          panel.background=element_blank(),

          axis.text=element_blank(),

          axis.ticks=element_blank(),

          axis.title=element_blank(),

          legend.position=c(0.02,0.6),

          )

          showtext.end()

          dev.off()

          4、哪些城市對實習(xí)僧的需要最為強(qiáng)烈?

          從第三個問題及其分析結(jié)果上我們已經(jīng)看出了整體形勢,北上廣深依然是需求最為旺盛的地區(qū),這也符合城市的實際經(jīng)濟(jì)發(fā)展情況及我們的預(yù)期。

          CairoPNG(file="E:/微信公眾號/公眾號——數(shù)據(jù)小魔方/2017年5月/20170512/jingjixue2.png",width=800,height=600)

          showtext.begin()

          ggplot(pointdata[1:20,],aes(reorder(Var1,Freq),Freq))+

          geom_bar(fill="#0C8DC4",stat="identity")+

          coord_flip()+

          labs(title="實習(xí)僧職位需求城市分布",caption="數(shù)據(jù)來源:實習(xí)僧官網(wǎng)")+

          geom_text(aes(y=Freq+25,label=Freq),hjust=2,colour="#C72E29",size=5)+

          theme_bw()+

          theme(

          panel.border=element_blank(),

          panel.grid.major=element_line(linetype="dashed"),

          panel.grid.minor=element_blank(),

          plot.title=element_text(size=15,colour="#003087",family="myfont"),

          plot.caption=element_text(hjust=0,size=10),

          axis.title=element_blank(),

          axis.text=element_text(size=15)

          )

          showtext.end()

          dev.off()

          5、實習(xí)工資大致什么水平,與城市和地域是否有關(guān)系?

          myjob_salary<-mydata[,c("address_unique","salary_low","salary_high")]

          myjob_salary$salary_low<-as.numeric(myjob_salary$salary_low)

          myjob_salary$salary_high<-as.numeric(myjob_salary$salary_high)

          myjob_salary<-na.omit(myjob_salary)%>%arrange(salary_high)%>%filter(salary_high>=20&salary_high<=500)

          myjob_salary$id<-seq_len(nrow(myjob_salary))

          myjob_salary$meansalary<-(myjob_salary$salary_low+myjob_salary$salary_high)/2

          CairoPNG(file="E:/微信公眾號/公眾號——數(shù)據(jù)小魔方/2017年5月/20170512/shixiseng_jobsaleryarea.png",width=1200,height=800)

          showtext.begin()

          ggplot(myjob_salary,aes(id))+

          geom_ribbon(aes(ymin=salary_low,ymax=salary_high),fill="grey70")+

          labs(title="實習(xí)僧職位工資區(qū)間分布",caption="數(shù)據(jù)來源:實習(xí)僧官網(wǎng)")+

          geom_line(aes(y=meansalary))+

          theme_minimal()+

          theme(

          panel.border=element_blank(),

          panel.grid.major=element_line(linetype="dashed"),

          panel.grid.minor=element_blank(),

          plot.title=element_text(size=30,colour="#003087",family="myfont"),

          plot.caption=element_text(hjust=0,size=20),

          axis.title=element_blank(),

          axis.text.y=element_text(size=15),

          axis.text.x=element_blank()

          )

          showtext.end()

          dev.off()

          myjob_salary$address_unique<-substr(myjob_salary$address_unique,1,2)

          myjobcitysalary<-aggregate(meansalary~address_unique,data=myjob_salary,FUN=mean)

          treemap(na.omit(myjobcitysalary), index=c("address_unique"),

          vSize="meansalary",title='實習(xí)僧職位薪酬地域分布圖',palette='RdBu',

          fontsize.title=18,fontsize.labels=12,fontface.labels="plain",

          fontfamily.title="mono",fontfamily.labels="mono")

          按照全部參與計算聚合的平均工資來看,北上廣深反而沒有什么吸引力了排名普遍不高,我猜想是因為一線城市的低工資職位數(shù)量過多,壓低了平均值。

          接下來我們按照100,150的臨界點進(jìn)行工資高低的劃分。

          salary100<-myjob_salary%>%filter(meansalary<=100)%>%select(address_unique)%>%table()%>%as.data.frame(stringsAsFactors=FALSE)

          salary100<-na.omit(salary100)%>%arrange(desc(Freq));names(salary100)<-c("city","num")

          CairoPNG(file="E:/微信公眾號/公眾號——數(shù)據(jù)小魔方/2017年5月/20170512/salary100.png",width=1200,height=900)

          showtext.begin()

          ggplot(salary100[salary100$num>=5,],aes(reorder(city,-num),num))+

          geom_bar(fill="#0C8DC4",stat="identity")+

          labs(title="實習(xí)僧職位薪資城市分布(日薪低于100)",caption="數(shù)據(jù)來源:實習(xí)僧官網(wǎng)")+

          geom_text(aes(y=num+10,label=num),hjust=.5,colour="#C72E29",size=5)+

          theme_bw()+

          theme(

          panel.border=element_blank(),

          panel.grid.major=element_line(linetype="dashed"),

          panel.grid.minor=element_blank(),

          plot.title=element_text(size=25,colour="#003087",family="myfont"),

          plot.caption=element_text(hjust=0,size=18),

          axis.title=element_blank(),

          axis.text=element_text(size=15)

          )

          showtext.end()

          dev.off()

          salary200<-myjob_salary%>%filter(meansalary>=200)%>%select(address_unique)%>%table()%>%as.data.frame(stringsAsFactors=FALSE)

          salary200<-na.omit(salary200)%>%arrange(desc(Freq));names(salary200)<-c("city","num")

          CairoPNG(file="E:/微信公眾號/公眾號——數(shù)據(jù)小魔方/2017年5月/20170512/salary200.png",width=1200,height=900)

          showtext.begin()

          ggplot(salary200,aes(reorder(city,-num),num))+

          geom_bar(fill="#0C8DC4",stat="identity")+

          labs(title="實習(xí)僧職位薪資城市分布(日薪高于200)",caption="數(shù)據(jù)來源:實習(xí)僧官網(wǎng)")+

          geom_text(aes(y=num+10,label=num),hjust=.5,colour="#C72E29",size=5)+

          theme_bw()+

          theme(

          panel.border=element_blank(),

          panel.grid.major=element_line(linetype="dashed"),

          panel.grid.minor=element_blank(),

          plot.title=element_text(size=25,colour="#003087",family="myfont"),

          plot.caption=element_text(hjust=0,size=18),

          axis.title=element_blank(),

          axis.text=element_text(size=15)

          )

          showtext.end()

          dev.off()

          salary100_200<-myjob_salary%>%filter(meansalary>100 & meansalary<200)%>%select(address_unique)%>%table()%>%as.data.frame(stringsAsFactors=FALSE)

          salary100_200<-na.omit(salary100_200)%>%arrange(desc(Freq));names(salary100_200)<-c("city","num")

          CairoPNG(file="E:/微信公眾號/公眾號——數(shù)據(jù)小魔方/2017年5月/20170512/salary100-200.png",width=1600,height=900)

          showtext.begin()

          ggplot(salary100_200,aes(reorder(city,-num),num))+

          geom_bar(fill="#0C8DC4",stat="identity")+

          labs(title="實習(xí)僧職位薪資城市分布(日薪處于100-200之間)",caption="數(shù)據(jù)來源:實習(xí)僧官網(wǎng)")+

          geom_text(aes(y=num+10,label=num),hjust=.5,colour="#C72E29",size=5)+

          theme_bw()+

          theme(

          panel.border=element_blank(),

          panel.grid.major=element_line(linetype="dashed"),

          panel.grid.minor=element_blank(),

          plot.title=element_text(size=25,colour="#003087",family="myfont"),

          plot.caption=element_text(hjust=0,size=18),

          axis.title=element_blank(),

          axis.text=element_text(size=15)

          )

          showtext.end()

          dev.off()

          分析到這里,趨勢已經(jīng)很明顯了,因為北上廣深等一線城市的職位實在是太多了,無論是高新職位還是低薪實習(xí)崗位都能排在全國各城市的前列,所以出現(xiàn)日均工資很普通的現(xiàn)象。相對而言,日薪在200以上的高薪職位更能代表各大城市對日常實習(xí)生需求的強(qiáng)烈程度,因為在這一階段,北上廣深的優(yōu)勢非常明顯,遙遙領(lǐng)先與其他二線城市,而針對日薪高于200的實習(xí)職位統(tǒng)計結(jié)果可以看出來,北上技壓群雄(不愧是帝都和魔都),深圳和廣州處于第二線,200以上的高新實習(xí)職位遇北上相比,相差比較大,僅占前兩者約1/3~1/5。而杭州、南京、武漢、合肥則穩(wěn)穩(wěn)處于第三梯隊。

          6、實習(xí)崗位一般都要求每周到崗多少天?

          myperiod<-mydata$period

          CairoPNG(file="E:/微信公眾號/公眾號——數(shù)據(jù)小魔方/2017年5月/20170512/internperiod.png",width=1000,height=750)

          showtext.begin()

          ggplot(data=NULL,aes(myperiod)) +

          geom_histogram(stat="count",show.legend=FALSE,binwidth=1,fill="#F86977",col=NA) +

          labs(title="實習(xí)職位要求每周工作天數(shù)",caption="數(shù)據(jù)來源:實習(xí)僧官網(wǎng)")+

          theme(panel.background=element_rect(fill=NA),

          plot.background=element_rect(fill=NA),

          plot.title=element_text(size=20,family="myfont"),

          plot.caption=element_text(hjust=0,family="myfont"),

          axis.line=element_line(colour="grey80"),

          axis.text=element_text(size=12,family="myfont"),

          axis.title=element_blank())

          showtext.end()

          dev.off()

          從分布上看,一周五天居多,這樣是正常的工作日現(xiàn)象。3天、4天也是用人單位補(bǔ)繳能接受的周工作天數(shù)。

          7、實習(xí)周期一般需要多長時間?

          myduration<-mydata$duration

          mydurationhz<-table(myduration)%>%as.data.frame(stringsAsFactors=FALSE)%>%arrange(desc(Freq))

          CairoPNG(file="E:/微信公眾號/公眾號——數(shù)據(jù)小魔方/2017年5月/20170512/internduration.png",width=1000,height=750)

          showtext.begin()

          ggplot(data=mydurationhz,aes(reorder(myduration,-Freq),Freq)) +

          geom_bar(stat="identity",show.legend=FALSE,width=1,fill="#065573",col=NA) +

          geom_text(aes(y=Freq+20,label=Freq),hjust=.5,colour="#C72E29",size=5)+

          labs(title="實習(xí)職位要求工作時間周期",caption="數(shù)據(jù)來源:實習(xí)僧官網(wǎng)")+

          theme(panel.background=element_rect(fill=NA),

          plot.background=element_rect(fill=NA),

          plot.title=element_text(size=20,family="myfont"),

          plot.caption=element_text(hjust=0,family="myfont"),

          axis.line=element_line(colour="grey80"),

          axis.text=element_text(size=12,family="myfont"),

          axis.title=element_blank())

          showtext.end()

          dev.off()

          8、哪些職位需求最為旺盛?

          下面開始分析最后一個問題,也是我認(rèn)為最有價值,最值得探究的問題,最后一個待分析指標(biāo)是實習(xí)職位,這個指標(biāo)跟我們最初分析的那個崗位性質(zhì)略有不同,該變量相對比較規(guī)范(職位類別有確定的預(yù)設(shè)范圍)。

          我們新建一個分析數(shù)據(jù),用職位、工資區(qū)間的中間值,地區(qū)三個變量進(jìn)行后續(xù)分析:

          mydata$salary_high<-as.numeric(mydata$salary_high)

          mydata$salary_low<-as.numeric(mydata$salary_low)

          mydata$salary_mean<-(mydata$salary_low+mydata$salary_high)/2

          myworkdata<-mydata[,c("address_unique","work","salary_mean")]

          首先分析下崗位的集中分布情況:

          myworkcount<-table(myworkdata[,2])%>%as.data.frame(stringsAsFactors=FALSE)%>%arrange(desc(Freq))

          CairoPNG(file="E:/微信公眾號/公眾號——數(shù)據(jù)小魔方/2017年5月/20170512/interndworkcount.png",width=1000,height=750)

          showtext.begin()

          ggplot(data=myworkcount,aes(reorder(Var1,-Freq),Freq)) +

          geom_bar(stat="identity",show.legend=FALSE,width=.75,fill="#5D8DA6",col=NA) +

          geom_text(aes(y=Freq+50,label=Freq),hjust=.5,colour="#C72E29",size=5)+

          labs(title="實習(xí)職位類別分布",caption="數(shù)據(jù)來源:實習(xí)僧官網(wǎng)")+

          theme(panel.background=element_rect(fill=NA),

          plot.background=element_rect(fill=NA),

          plot.title=element_text(size=20,family="myfont"),

          plot.caption=element_text(hjust=0,family="myfont"),

          axis.line=element_line(colour="grey80"),

          axis.text=element_text(size=12,family="myfont"),

          axis.title=element_blank())

          showtext.end()

          dev.off()

          各個崗位工資分布:

          myworkmean<-aggregate(salary_mean~work,data=myworkdata,FUN=mean)

          CairoPNG(file="E:/微信公眾號/公眾號——數(shù)據(jù)小魔方/2017年5月/20170512/interndworkmean.png",width=1000,height=750)

          showtext.begin()

          ggplot(data=myworkmean,aes(reorder(work,-salary_mean),salary_mean)) +

          geom_bar(stat="identity",show.legend=FALSE,width=.75,fill="#5D8DA6",col=NA) +

          geom_text(aes(y=salary_mean+5,label=round(salary_mean,1)),hjust=.5,colour="#C72E29",size=10)+

          labs(title="實習(xí)職位類別平均工資",caption="數(shù)據(jù)來源:實習(xí)僧官網(wǎng)")+

          theme(panel.background=element_rect(fill=NA),

          plot.background=element_rect(fill=NA),

          plot.title=element_text(size=25,family="myfont"),

          plot.caption=element_text(hjust=0,family="myfont",size=20),

          axis.line=element_line(colour="grey80"),

          axis.text=element_text(size=18,family="myfont"),

          axis.title=element_blank())

          showtext.end()

          dev.off()

          從工資均數(shù)上來看,七大類職位差距不大,說明僅就實習(xí)崗位工資而言,結(jié)合爬取的總體樣本,不考慮地域差異,實習(xí)工資差異不很明顯。也許是因為實習(xí)崗位中真正有含金量的并不多,換句話說,企業(yè)的高價值崗位,對于工作經(jīng)驗、技能的要求相對較高,而實習(xí)生則在這方面都不具備優(yōu)勢。(如果是社招或者小校招崗位信息的話,可能工資均值的差異會大一些)。

          最后,讓我們用一個桑基圖來完結(jié)本次針對實習(xí)僧網(wǎng)站的爬蟲分析:

          write.table (myworkdata,"D:/R/File/shixiseng_workdata.csv",sep=",",row.names=FALSE)

          桑基流向圖的趨勢灰常明顯,北上兩市在所有類別職位(7大類)上均居前列,各職位類別中,市場和運營職位需求最為強(qiáng)烈,北京和上海在對市場和運營職位的需求容量機(jī)會平分秋色。廣州和深圳仍然略于北上,但是與其他二線城市相比較,優(yōu)勢仍然很明顯。(也許是因為實習(xí)僧做為主打校園實習(xí)崗位信息咨詢平臺,針對的主流群體基本以在校大學(xué)生為主,而北上廣深的高等教育資源分布差異明顯,在高校數(shù)量方面,北上的要沾光很多,廣州與深圳的高校資源相對比較匱乏,在以上分析的各項指標(biāo)中都占盡劣勢)。

          爬蟲和代碼分析,算起來整整花了將近12個小時,雖然分析的不是很精準(zhǔn)、客觀,但是過程還是很有收獲的,期待下一次做的更好!

          End.

          來源:R語言中文社區(qū)

          國統(tǒng)計網(wǎng),是國內(nèi)最早的大數(shù)據(jù)學(xué)習(xí)網(wǎng)站,歡迎關(guān)注!

          I 鑒賞

          早幾年學(xué)習(xí)前端,大家都非常熱衷于研究jQuery源碼。

          我至今還記得當(dāng)初從jQuery源碼中學(xué)到一星半點應(yīng)用技巧的時候常會有一種發(fā)自內(nèi)心的驚嘆,“原來JavaScript居然可以這樣用!”

          但是隨著前端的迅猛發(fā)展,另外幾種前端框架的崛起,jQuery慢慢變得不再是必須。所有人對jQuery的熱情都降低了許多。

          jQuery在前端史上有它非常超然的歷史地位,許多從中學(xué)到的技巧在實踐開發(fā)中仍然非常好用。簡單的了解它有助于我們更加深入的理解JavaScript。如果你能夠從中看明白jquery是如何一步步被取代的,那么,我想你的收益遠(yuǎn)不止學(xué)會使用了一個庫那么簡單。

          因此,我的態(tài)度是,項目中你可以不用,但是我仍然建議你學(xué)。

          這篇文章的主要目的,是從面向?qū)ο蟮慕嵌龋蠹曳窒韏query對象是如何封裝的。算是對大家進(jìn)一步學(xué)習(xí)jQuery源碼的一個拋磚引玉。

          1

          使用jQuery對象時,我們這樣寫:

          // 聲明一個jQuery對象
          $('.target')
          
          // 獲取元素的css屬性
          $('.target').css('width')
          
          // 獲取元素的位置信息
          $('.target').offset()
          

          在使用之初可能會有許多疑問,比如$是怎么回事?為什么不用new就可以直接聲明一個對象?等等。了解之后,才知道原來這正是jQuery對象創(chuàng)建的巧妙之處。

          先直接用代碼展示出來,再用圖跟大家解釋是怎么回事。

          ;
          (function (ROOT) {
          
            // 構(gòu)造函數(shù)
            var jQuery=function (selector) {
          
              // 在jQuery中直接返回new過的實例,這里的init是jQuery的真正構(gòu)造函數(shù)
              return new jQuery.fn.init(selector)
            }
          
            jQuery.fn=jQuery.prototype={
              constructor: jQuery,
          
              version: '1.0.0',
          
              init: function (selector) {
                // 在jquery中這里有一個復(fù)雜的判斷,但是這里我做了簡化
                var elem, selector;
                elem=document.querySelector(selector);
                this[0]=elem;
          
                // 在jquery中返回一個由所有原型屬性方法組成的數(shù)組,我們這里簡化,直接返回this即可
                // return jQuery.makeArray(selector, this);
                return this;
              },
          
              // 在原型上添加一堆方法
              toArray: function () { },
              get: function () { },
              each: function () { },
              ready: function () { },
              first: function () { },
              slice: function () { }
              // ... ...
            }
          
            jQuery.fn.init.prototype=jQuery.fn;
          
            // 實現(xiàn)jQuery的兩種擴(kuò)展方式
            jQuery.extend=jQuery.fn.extend=function (options) {
          
              // 在jquery源碼中會根據(jù)參數(shù)不同進(jìn)行很多判斷,我們這里就直接走一種方式,所以就不用判斷了
              var target=this;
              var copy;
          
              for (name in options) {
                copy=options[name];
                target[name]=copy;
              }
              return target;
            }
          
            // jQuery中利用上面實現(xiàn)的擴(kuò)展機(jī)制,添加了許多方法,其中
          
            // 直接添加在構(gòu)造函數(shù)上,被稱為工具方法
            jQuery.extend({
              isFunction: function () { },
              type: function () { },
              parseHTML: function () { },
              parseJSON: function () { },
              ajax: function () { }
              // ...
            })
          
            // 添加到原型上
            jQuery.fn.extend({
              queue: function () { },
              promise: function () { },
              attr: function () { },
              prop: function () { },
              addClass: function () { },
              removeClass: function () { },
              val: function () { },
              css: function () { }
              // ...
            })
          
            // $符號的由來,實際上它就是jQuery,一個簡化的寫法,在這里我們還可以替換成其他可用字符
            ROOT.jQuery=ROOT.$=jQuery;
          })(window);
          

          在上面的代碼中,我封裝了一個簡化版的jQuery對象。

          它向大家簡單展示了jQuery的整體骨架。

          在代碼中可以看到,jQuery自身對于原型的處理使用了一些巧妙的方式,比如jQuery.fn=jQuery.prototype,jQuery.fn.init.prototype=jQuery.fn;等,這幾句正是jQuery對象的關(guān)鍵所在。看圖分析。

          jQuery對象核心圖

          2

          對象封裝分析

          在上面的實現(xiàn)中,首先在jQuery構(gòu)造函數(shù)里聲明了一個fn屬性,并將其指向了原型jQuery.prototype。然后在原型中添加了init方法。

          jQuery.fn=jQuery.prototype={
            init: {}
          }
          

          之后又將init的原型,指向了jQuery.prototype。

          jQuery.fn.init.prototype=jQuery.fn;
          

          而在構(gòu)造函數(shù)jQuery中,返回了init的實例對象。

          var jQuery=function (selector) {
          
            // 在jQuery中直接返回new過的實例,這里的init是jQuery的真正構(gòu)造函數(shù)
            return new jQuery.fn.init(selector)
          }
          

          最后對外暴露入口時,將字符$與jQuery對等起來。

          ROOT.jQuery=ROOT.$=jQuery;
          

          因此當(dāng)我們直接使用$('#test')創(chuàng)建一個對象時,實際上是創(chuàng)建了一個init的實例,這里的真正構(gòu)造函數(shù)是原型中的init方法。

          注意:許多對jQuery內(nèi)部實現(xiàn)不太了解的盆友,常常會毫無節(jié)制使用$(),比如對于同一個元素的不同操作:

          var width=parseInt($('#test').css('width'));
          if(width > 20) {
            $('#test').css('backgroundColor', 'red');
          }
          

          通過我們上面的一系列分析,我們知道每當(dāng)我們執(zhí)行$()時,就會重新生成一個init的實例對象,因此當(dāng)我們這樣沒有節(jié)制的使用jQuery是非常不正確的,雖然看上去方便了一些,但是對于內(nèi)存的消耗非常大。正確的做法是既然是同一個對象,那么就用一個變量保存起來后續(xù)使用即可。

          var $test=$('#test');
          var width=parseInt($test.css('width'));
          if(width > 20) {
            $test.css('backgroundColor', 'red');
          }
          

          3

          擴(kuò)展方法分析

          在上面的代碼實現(xiàn)中,我還簡單實現(xiàn)了兩個擴(kuò)展方法。

          jQuery.extend=jQuery.fn.extend=function (options) {
          
            // 在jquery源碼中會根據(jù)參數(shù)不同進(jìn)行很多判斷,我們這里就直接走一種方式,所以就不用判斷了
            var target=this;
            var copy;
          
            for (name in options) {
              copy=options[name];
              target[name]=copy;
            }
            return target;
          }
          

          要理解它的實現(xiàn),首先要明確知道this的指向。如果你搞不清楚,可以回頭去看看我們之前關(guān)于this指向的講解。

          傳入的參數(shù)options為一個key: value模式的對象,我通過for in遍歷options,將key作為jQuery的新屬性,value作為該新屬性所對應(yīng)的新方法,分別添加到j(luò)Query方法和jQuery.fn中。

          也就是說,當(dāng)我們通過jQuery.extend擴(kuò)展jQuery時,方法被添加到了jQuery構(gòu)造函數(shù)中,而當(dāng)我們通過jQuery.fn.extend擴(kuò)展jQuery時,方法被添加到了jQuery原型中。

          上面的例子中,我也簡單展示了在jQuery內(nèi)部,許多方法的實現(xiàn)都是通過這兩個擴(kuò)展方法來完成的。

          當(dāng)我們通過上面的知識了解了jQuery的大體框架之后,我們對于jQuery的學(xué)習(xí)就可以具體到諸如css/val/attr等方法是如何實現(xiàn)這樣的程度,那么源碼學(xué)習(xí)起來就會輕松很多,節(jié)省更多的時間。也給一些對于源碼敬而遠(yuǎn)之的朋友提供一個學(xué)習(xí)的可能。

          4

          有一個朋友留言給我,說她被靜態(tài)方法,工具方法和實例方法這幾個概念困擾了很久,到底他們有什么區(qū)別?

          其實在上一篇文章中,關(guān)于封裝一個對象,我跟大家分享了一個非常非常干,但是卻只有少數(shù)幾個讀者大佬g(shù)et到的知識,那就是在封裝對象時,屬性和方法可以具體放置的三個位置,并且對于這三個位置的不同做了一個詳細(xì)的解讀。

          image.png

          在實現(xiàn)jQuery擴(kuò)展方法時,一部分方法需要擴(kuò)展到構(gòu)造函數(shù)中,一部分方法需要擴(kuò)展到原型中,當(dāng)我們通讀jQuery源碼時,還發(fā)現(xiàn)有一些方法放在了模塊作用域中,至于為什么會有這樣的區(qū)別,建議大家回過頭去讀讀前一篇文章。

          這里用一個例子簡單區(qū)分一下。

          // 模塊內(nèi)部
          const a=20;
          
          function Person(name, age) {
            this.name=name;
            this.age=age;
            // 構(gòu)造函數(shù)方法,每聲明一個實例,都會重新創(chuàng)建一次,屬于實例獨有
            this.getName=function() {
              return this.name;
            }
          }
          
          // 原型方法,僅在原型創(chuàng)建時聲明一次,屬于所有實例共享
          Person.prototype.getAge=function() {
            return this.age;
          }
          
          // 工具方法,直接掛載在構(gòu)造函數(shù)名上,僅聲明一次,無法直接訪問實例內(nèi)部屬性與方法
          Person.each=function() {}
          

          如上例中,each就是一個工具方法,或者說靜態(tài)方法。

          工具方法的特性也和工具一詞非常貼近,他們與實例的自身屬性毫無關(guān)聯(lián),僅僅只是實現(xiàn)一些通用的功能,我們可以通過$.each與$('div').each這2個方法來體會工具方法與實例方法的不同之處。

          在實際開發(fā)中,我們運用得非常多的一個工具庫就是lodash.js,大家如果時間充裕一定要去學(xué)習(xí)一下他的使用。

          $.ajax()
          $.isFunction()
          $.each()
          ... ...
          

          放在原型中的方法,在使用時必須創(chuàng)建了一個新的實例對象才能訪問,因此這樣的方法叫做實例方法。也正是因為這一點,他的使用成本會比工具方法高一些。但是相比構(gòu)造函數(shù)方法,原型方法更節(jié)省內(nèi)存。

          $('#test').css()
          $('#test').attr()
          $('div').each()
          

          這樣,那位同學(xué)的疑問就被搞定啦。我們在學(xué)習(xí)的時候,一定不要過分去糾結(jié)一些概念,而要明白這些概念背后的具體場景是怎么回事兒,那么學(xué)習(xí)這件事情就不會在一些奇奇怪怪的地方卡住了。

          所以通過$.extend擴(kuò)展的方法,其實就是對工具方法的擴(kuò)展,而通過$.fn.extend擴(kuò)展的方法,就是對于實例方法的擴(kuò)展。

          5

          jQuery插件的實現(xiàn)

          我在初級階段時,覺得要自己編寫一個jQuery插件是超級高大上的事情,可望不可即。但是通過對于上面的理解,我就知道擴(kuò)展jQuery插件其實是一件我們自己也可以完成的事情。

          在前面我跟大家分享了jQuery如何實現(xiàn),以及他們的方法如何擴(kuò)展,并且前一篇文章分享了拖拽對象的具體實現(xiàn)。所以建議大家暫時不要閱讀下去,自己動手嘗試將拖拽擴(kuò)展成為jQuery的一個實例方法,這就是一個jQuery插件了。

          具體也沒有什么可多說的了,大家看了代碼就可以明白一切。

          // Drag對象簡化代碼,完整源碼可在上一篇文章中查看
          ;
          (function () {
          
            // 構(gòu)造
            function Drag(selector) { }
          
          
            // 原型
            Drag.prototype={
              constructor: Drag,
          
              init: function () {
                // 初始時需要做些什么事情
                this.setDrag();
              },
          
              // 稍作改造,僅用于獲取當(dāng)前元素的屬性,類似于getName
              getStyle: function (property) { },
          
              // 用來獲取當(dāng)前元素的位置信息,注意與之前的不同之處
              getPosition: function () { },
          
              // 用來設(shè)置當(dāng)前元素的位置
              setPostion: function (pos) { },
          
              // 該方法用來綁定事件
              setDrag: function () { }
            }
          
            // 一種對外暴露的方式
            window.Drag=Drag;
          })();
          
          // 通過擴(kuò)展方法將拖拽擴(kuò)展為jQuery的一個實例方法
          (function ($) {
            $.fn.extend({
              becomeDrag: function () {
                new Drag(this[0]);
                return this;   // 注意:為了保證jQuery所有的方法都能夠鏈?zhǔn)皆L問,每一個方法的最后都需要返回this,即返回jQuery實例
              }
            })
          })(jQuery);
          

          下一篇:前端基礎(chǔ)進(jìn)階(十四):深入核心,詳解事件循環(huán)機(jī)制

          建議收藏,不然刷著刷著就可能找不到了

          有什么前端的問題歡迎私信我~期待你的到來。

          我自己是一名從事了多年開發(fā)的web前端老程序員,目前辭職在做自己的web前端私人定制課程,今年我花了一個月整理了一份最適合2020年學(xué)習(xí)的web前端學(xué)習(xí)干貨,各種框架都有整理,送給每一位前端小伙伴,想要獲取的可以關(guān)注我的頭條號并在后臺私信我:前端,即可免費獲取

          i,大家好,我是拾光。

          今天給大家?guī)淼氖莏s實現(xiàn)文本框自動填充。

          下面貼圖:

          HTML:

          <!doctype html>

          <html>

          <head>

          <meta charset="UTF-8">

          <title>Document</title>

          <script src="jquery-1.8.3.min.js"></script>

          <style>

          *{

          margin:0;

          padding:0;

          }

          ul,li{

          list-style:none;

          }

          .inputElem {

          width:198px;

          height:22px;

          line-height:22px;

          border:1px solid #ff4455;

          }

          .parentCls

          {

          width:200px;

          }

          .auto-tip li

          {

          width:100%;

          height:22px;

          line-height:22px;

          font-size:14px;

          }

          .auto-tip li.hoverBg{

          background:#ddd;

          cursor:pointer;

          }

          .red

          {

          color:red;

          }

          .hidden {

          display:none;

          }

          </style>

          <script src="emailAutoComplete.js"></script>

          </head>

          <body>

          <div>

          <input type="text">

          </div>

          </body>

          </html>

          JS:

          function EmailAutoComplete(options) {

          this.config={

          targetCls : '.inputElem',

          parentCls : '.parentCls',

          hiddenCls : '.hiddenCls',

          searchForm : '.jqtransformdone',

          hoverBg : 'hoverBg',

          inputValColor : 'red',

          mailArr : ["@qq.com","@qq2.com","@gmail.com","@126.com","@163.com","@hotmail.com","@yahoo.com","@yahoo.com.cn","@live.com","@sohu.com","@sina.com"],

          isSelectHide : true,

          callback : null

          };

          this.cache={

          onlyFlag : true,

          currentIndex : -1,

          oldIndex : -1

          };

          this.init(options);

          }

          EmailAutoComplete.prototype={

          constructor: EmailAutoComplete,

          init: function(options){

          this.config=$.extend(this.config,options || {});

          var self=this,

          _config=self.config,

          _cache=self.cache;

          $(_config.targetCls).each(function(index,item){

          $(item).keyup(function(e){

          var target=e.target,

          targetVal=$.trim($(this).val()),

          keycode=e.keyCode,

          elemHeight=$(this).outerHeight(),

          elemWidth=$(this).outerWidth(),

          parentNode=$(this).closest(_config.parentCls);

          $(parentNode).css({'position':'relative'});

          if(targetVal=='') {

          $(item).attr({'data-html':''});

          $(_config.hiddenCls,parentNode).val('');

          _cache.currentIndex=-1;

          _cache.oldIndex=-1;

          $(".auto-tip",parentNode) && !$(".auto-tip",parentNode).hasClass('hidden') && $(".auto-tip",parentNode).addClass('hidden');

          self._removeBg(parentNode);

          }else {

          $(item).attr({'data-html':targetVal});

          $(_config.hiddenCls,parentNode).val(targetVal);

          $(".auto-tip",parentNode) && $(".auto-tip",parentNode).hasClass('hidden') && $(".auto-tip",parentNode).removeClass('hidden');

          self._renderHTML({keycode:keycode,e:e,target:target,targetVal:targetVal,height:elemHeight,width:elemWidth,parentNode:parentNode});

          }

          });

          });

          $(_config.searchForm).each(function(index,item) {

          $(item).keydown(function(e){

          var keyCode=e.keyCode;

          if(keyCode==13) {

          return false;

          }

          });

          });

          $(document).click(function(e){

          e.stopPropagation();

          var target=e.target,

          tagCls=_config.targetCls.replace(/^\./,'');

          if(!$(target).hasClass(tagCls)) {

          $('.auto-tip') && $('.auto-tip').each(function(index,item){

          !$(item).hasClass('hidden') && $(item).addClass('hidden');

          });

          }

          });

          },

          _renderHTML: function(cfg) {

          var self=this,

          _config=self.config,

          _cache=self.cache,

          curVal;

          var curIndex=self._keyCode(cfg.keycode);

          $('.auto-tip',cfg.parentNode).hasClass('hidden') && $('.auto-tip',cfg.parentNode).removeClass('hidden');

          if(curIndex > -1){

          self._keyUpAndDown(cfg.targetVal,cfg.e,cfg.parentNode);

          }else {

          if(/@/.test(cfg.targetVal)) {

          curVal=cfg.targetVal.replace(/@.*/,'');

          }else {

          curVal=cfg.targetVal;

          }

          if(_cache.onlyFlag) {

          $(cfg.parentNode).append('<input type="hidden" class="hiddenCls"/>');

          var wrap='<ul class="auto-tip">';

          for(var i=0; i < _config.mailArr.length; i++) {

          wrap +='<li class="p-index'+i+'">'+'<span class="output-num"></span><em class="em" data-html="'+_config.mailArr[i]+'">'+_config.mailArr[i]+'</em></li>';

          }

          wrap +='</ul>';

          _cache.onlyFlag=false;

          $(cfg.parentNode).append(wrap);

          $('.auto-tip',cfg.parentNode).css({'position':'absolute','top':cfg.height,'width':cfg.width - 2 + 'px','left':0,

          'border':'1px solid #ccc','z-index':10000});

          }

          $('.auto-tip li',cfg.parentNode).each(function(index,item){

          $('.output-num',item).html(curVal);

          !$('.output-num',item).hasClass(_config.inputValColor) &&

          $('.output-num',item).addClass(_config.inputValColor);

          var emVal=$.trim($('.em',item).attr('data-html'));

          $(item).attr({'data-html':curVal + '' +emVal});

          });

          self._accurateMate({target:cfg.target,parentNode:cfg.parentNode});

          self._itemHover(cfg.parentNode);

          self._executeClick(cfg.parentNode);

          }

          },

          _accurateMate: function(cfg) {

          var self=this,

          _config=self.config,

          _cache=self.cache;

          var curVal=$.trim($(cfg.target,cfg.parentNode).attr('data-html')),

          newArrs=[];

          if(/@/.test(curVal)) {

          var prefix=curVal.replace(/@.*/, ""),

          suffix=curVal.replace(/.*@/, "");

          $.map(_config.mailArr,function(n){

          var reg=new RegExp(suffix);

          if(reg.test(n)) {

          newArrs.push(n);

          }

          });

          if(newArrs.length > 0) {

          $('.auto-tip',cfg.parentNode).html('');

          $(".auto-tip",cfg.parentNode) && $(".auto-tip",cfg.parentNode).hasClass('hidden') &&

          $(".auto-tip",cfg.parentNode).removeClass('hidden');

          var html='';

          for(var j=0, jlen=newArrs.length; j < jlen; j++) {

          html +='<li class="p-index'+j+'">'+'<span class="output-num"></span><em class="em" data-html="'+newArrs[j]+'">'+newArrs[j]+'</em></li>';

          }

          $('.auto-tip',cfg.parentNode).html(html);

          $('.auto-tip li',cfg.parentNode).each(function(index,item){

          $('.output-num',item).html(prefix);

          !$('.output-num',item).hasClass(_config.inputValColor) &&

          $('.output-num',item).addClass(_config.inputValColor);

          var emVal=$.trim($('.em',item).attr('data-html'));

          $(item).attr('data-html','');

          $(item).attr({'data-html':prefix + '' +emVal});

          });

          _cache.currentIndex=-1;

          _cache.oldIndex=-1;

          $('.auto-tip .output-num',cfg.parentNode).html(prefix);

          self._itemHover(cfg.parentNode);

          self._executeClick(cfg.parentNode);

          }else {

          $(".auto-tip",cfg.parentNode) && !$(".auto-tip",cfg.parentNode).hasClass('hidden') &&

          $(".auto-tip",cfg.parentNode).addClass('hidden');

          $('.auto-tip',cfg.parentNode).html('');

          }

          }

          },

          _itemHover: function(parentNode) {

          var self=this,

          _config=self.config,

          _cache=self.cache;

          $('.auto-tip li',parentNode).hover(function(index,item) {

          !$(this).hasClass(_config.hoverBg) && $(this).addClass(_config.hoverBg);

          },function() {

          $(this).hasClass(_config.hoverBg) && $(this).removeClass(_config.hoverBg);

          });

          },

          _removeBg: function(parentNode){

          var self=this,

          _config=self.config;

          $(".auto-tip li",parentNode).each(function(index,item){

          $(item).hasClass(_config.hoverBg) && $(item).removeClass(_config.hoverBg);

          });

          },

          _keyUpAndDown: function(targetVal,e,parentNode) {

          var self=this,

          _cache=self.cache,

          _config=self.config;

          if($('.auto-tip' + ' li',parentNode) && $('.auto-tip' + ' li').length > 0) {

          var plen=$('.auto-tip' + ' li',parentNode).length,

          keyCode=e.keyCode;

          _cache.oldIndex=_cache.currentIndex;

          if(keyCode==38) {

          if(_cache.currentIndex==-1) {

          _cache.currentIndex=plen - 1;

          }else {

          _cache.currentIndex=_cache.currentIndex - 1;

          if(_cache.currentIndex < 0) {

          _cache.currentIndex=plen - 1;

          }

          }

          if(_cache.currentIndex !==-1) {

          !$('.auto-tip .p-index'+_cache.currentIndex,parentNode).hasClass(_config.hoverBg) &&

          $('.auto-tip .p-index'+_cache.currentIndex,parentNode).addClass(_config.hoverBg).siblings().removeClass(_config.hoverBg);

          var curAttr=$('.auto-tip' + ' .p-index'+_cache.currentIndex,parentNode).attr('data-html');

          $(_config.targetCls,parentNode).val(curAttr);

          $(_config.hiddenCls,parentNode).val(curAttr);

          }

          }else if(keyCode==40) {

          if(_cache.currentIndex==plen - 1) {

          _cache.currentIndex=0;

          }else {

          _cache.currentIndex++;

          if(_cache.currentIndex > plen - 1) {

          _cache.currentIndex=0;

          }

          }

          if(_cache.currentIndex !==-1) {

          !$('.auto-tip .p-index'+_cache.currentIndex,parentNode).hasClass(_config.hoverBg) &&

          $('.auto-tip .p-index'+_cache.currentIndex,parentNode).addClass(_config.hoverBg).siblings().removeClass(_config.hoverBg);

          var curAttr=$('.auto-tip' + ' .p-index'+_cache.currentIndex,parentNode).attr('data-html');

          $(_config.targetCls,parentNode).val(curAttr);

          $(_config.hiddenCls,parentNode).val(curAttr);

          }

          }else if(keyCode==13) {

          var curVal=$('.auto-tip' + ' .p-index'+_cache.oldIndex,parentNode).attr('data-html');

          $(_config.targetCls,parentNode).val(curVal);

          $(_config.hiddenCls,parentNode).val(curVal);

          if(_config.isSelectHide) {

          !$(".auto-tip",parentNode).hasClass('hidden') && $(".auto-tip",parentNode).addClass('hidden');

          }

          _config.callback && $.isFunction(_config.callback) && _config.callback();

          _cache.currentIndex=-1;

          _cache.oldIndex=-1;

          }

          }

          },

          _keyCode: function(code) {

          var arrs=['17','18','38','40','37','39','33','34','35','46','36','13','45','44','145','19','20','9'];

          for(var i=0, ilen=arrs.length; i < ilen; i++) {

          if(code==arrs[i]) {

          return i;

          }

          }

          return -1;

          },

          _executeClick: function(parentNode) {

          var _self=this,

          _config=_self.config;

          $('.auto-tip' + ' li',parentNode).unbind('click');

          $('.auto-tip' + ' li',parentNode).bind('click',function(e){

          var dataAttr=$(this).attr('data-html');

          $(_config.targetCls,parentNode).val(dataAttr);

          if(_config.isSelectHide) {

          !$(".auto-tip",parentNode).hasClass('hidden') && $(".auto-tip",parentNode).addClass('hidden');

          }

          $(_config.hiddenCls,parentNode).val(dataAttr);

          _config.callback && $.isFunction(_config.callback) && _config.callback();

          });

          }

          };

          $(function() {

          new EmailAutoComplete({});

          });

          今天就到這里咯~

          大家研究一下吧~

          希望大家過的愉快。

          Best wishes to you.

          LiuDongYu.


          主站蜘蛛池模板: 日韩在线视频一区二区三区| 狠狠爱无码一区二区三区| 国产精品无码一区二区三区不卡| 视频一区二区三区免费观看| 亚洲综合色一区二区三区| 国模吧一区二区三区| 一区二区乱子伦在线播放| 亚洲高清成人一区二区三区| 日美欧韩一区二去三区| 91国偷自产一区二区三区| 久久高清一区二区三区| 国产无套精品一区二区| 99久久精品国产免看国产一区| 在线观看精品一区| 日本一区免费电影| 日本一区高清视频| 国产一区二区三区免费在线观看| 日韩精品一区二区三区大桥未久| 精品国产一区二区三区av片| 亚洲综合av一区二区三区| 亚洲视频一区调教| 性无码免费一区二区三区在线| 中文字幕一区二区日产乱码| 日韩动漫av在线播放一区| 日韩一区二区在线免费观看| 国模无码视频一区| 国内精品视频一区二区三区八戒| 日本在线视频一区二区| 在线日产精品一区| 精品一区二区视频在线观看| 中文字幕日韩一区| 久久久精品人妻一区二区三区四 | 亚洲日本一区二区| 精品一区二区三区东京热| 少妇无码一区二区三区| 人妻无码一区二区三区免费| 无码人妻一区二区三区在线| 无码人妻精品一区二区三区在线 | 国产精品久久久久一区二区三区| 精品香蕉一区二区三区| 日本一区二区三区不卡视频|