利用Python獲取趕集網(wǎng)招聘信息前篇
如何獲取一個(gè)網(wǎng)站的相關(guān)信息,獲取趕集網(wǎng)的招聘信息,本文為大家介紹利用python獲取趕集網(wǎng)招聘信息的關(guān)鍵代碼,供大家參考,具體內(nèi)容如下
import re
import urllib
import urllib.request
#獲取趕集網(wǎng)數(shù)據(jù)
def begin(url):
#要偽裝成的瀏覽器(我這個(gè)是用的chrome)
headers = ('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36')
opener = urllib.request.build_opener()
#將要偽裝成的瀏覽器添加到對(duì)應(yīng)的http頭部
opener.addheaders=[headers]
#讀取相應(yīng)的url
data = opener.open(url).read()
#將獲得的html解碼為utf-8
data=data.decode('utf-8')
return data
#處理數(shù)據(jù),返回字典城市對(duì)應(yīng)城市的url
def get_cityinfo(data):
city_info1=re.findall(r'dl>(.*?)</dl>',data,re.S)
city_info2=re.findall(r'(<a.*?</a>)',city_info1[0],re.S)
city_dict={}
for each in city_info2:
key=re.findall('>(.*?)</',each,re.S)
city_url=re.findall('href="(.*?)"',each,re.S)
city_dict[key[0]]=city_url[0]
return city_dict
#獲取所有的a標(biāo)簽,并從a標(biāo)簽中獲取信息
def a_info(data):
a_info=re.findall(r'(<a.*?</a>)',data[0],re.S)
a_dict={}
for each in a_info:
key=re.findall('>(.*?)</',each,re.S)
a_url=re.findall('"(.*?)"',each,re.S)
a_dict[key[0]]=a_url[0]
return a_dict
#獲取對(duì)應(yīng)城市信息的所有分類
def get_cityinfoclass():
#目前先獲取招聘信息,后面有時(shí)間再繼續(xù)補(bǔ)充完善這個(gè)模塊
info= 'zhaopin/'
return info
#獲取對(duì)應(yīng)城市和其城市分類的信息
def getzhaopin(city_info,infoclass):
#先搞成都的信息招聘
city_url=city_info['成都']
cdzp_url=city_url+infoclass
cdzp_info=begin(cdzp_url)
return city_url,cdzp_info
#獲取成都市招聘信息
def get_zhaopin_info(city_url,cdzp_info):
allzp_info=re.findall('class="f-all-news"(.*?)</div>',cdzp_info,re.S)
a_dict={}
class_info=re.findall('<dd>(.*?)</dd>',allzp_info[0],re.S)
for each in class_info:
a_info=re.findall(r'(<a.*?</a>)',each,re.S)
for each1 in a_info:
key=re.findall('>(.*?)</',each1,re.S)
a_url=re.findall('href="/(.*?)"',each1,re.S)
a_dict[key[0].strip()]=city_url+a_url[0]
return a_dict
#獲取招聘信息的具體內(nèi)容
def get_city_zpinfo_detail(url):
#先獲取軟件工程師
sorft_engineer=(zp_class_info['軟件工程師'])
job_url_info=begin(sorft_engineer)
get_detail_info(job_url_info)
#處理詳情頁(yè)的信息
def get_detail_info(list_info):
job_info=re.findall('<dl class="list-noimg job-list clearfix"(.*?)</dl',list_info,re.S)
print(job_info[0])
if __name__=='__main__':
url='http://www.ganji.com/index.htm';
data=begin(url);
#所有城市信息
city_info=get_cityinfo(data)
#對(duì)應(yīng)的分類
infoclass=get_cityinfoclass()
cdzp_url,xiaoshou=getzhaopin(city_info,infoclass)
#獲取招聘的分類信息
zp_class_info=get_zhaopin_info(cdzp_url,xiaoshou)
get_city_zpinfo_detail(zp_class_info)
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助。
相關(guān)文章
python3 讀取Excel表格中的數(shù)據(jù)
這篇文章主要介紹了python3 讀取Excel表格中的數(shù)據(jù)的相關(guān)資料,需要的朋友可以參考下2018-10-10
我用Python抓取了7000 多本電子書(shū)案例詳解
這篇文章主要介紹了我用Python抓取了7000 多本電子書(shū)案例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-03-03
使用pyqt 實(shí)現(xiàn)重復(fù)打開(kāi)多個(gè)相同界面
今天小編就為大家分享一篇使用pyqt 實(shí)現(xiàn)重復(fù)打開(kāi)多個(gè)相同界面,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-12-12
Win10系統(tǒng)下安裝labelme及json文件批量轉(zhuǎn)化方法
這篇文章主要介紹了Win10系統(tǒng)下安裝labelme及json文件批量轉(zhuǎn)化的方法,文中較詳細(xì)的給大家介紹了安裝過(guò)程 ,需要的朋友可以參考下2019-07-07
citespace數(shù)據(jù)處理:用python對(duì)Ref文檔進(jìn)行去重方式
這篇文章主要介紹了citespace數(shù)據(jù)處理:用python對(duì)Ref文檔進(jìn)行去重方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-11-11
python實(shí)現(xiàn)撲克牌交互式界面發(fā)牌程序
這篇文章主要介紹了python實(shí)現(xiàn)撲克牌交互式界面發(fā)牌程序,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-04-04
不到20行實(shí)現(xiàn)Python代碼即可制作精美證件照
這篇文章主要介紹了不到20行實(shí)現(xiàn)Python代碼即可制作精美證件照,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04

