摘要:本文实例为大家分享了python语言爬取51job中hr的邮箱具体代码,供大家参考,具体内容如下,希望对大家学习python语言有所帮助。
本文实例为大家分享了python语言爬取51job中hr的邮箱具体代码,供大家参考,具体内容如下,希望对大家学习python语言有所帮助。
#encoding=utf8 <d>import</d> urllib2 <d>import</d> cookielib <d>import</d> re <d>import</d> lxml.html from _ast <d>import</d> TryExcept from warnings <d>import</d> catch_warnings f = open('/root/Desktop/51-01.txt','a+') def read(city): url = '//www.51job.com/'+city cj = cookielib.MozillaCookieJar() cookie_support = urllib2.HTTPCookieProcessor(cj) opener = urllib2.build_opener(cookie_support) opener.addheaders = [('User-agent','Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0 Iceweasel/38.3.0')] urllib2.install_opener(opener) response = urllib2.urlopen(url) http = response.read() rex = '//jobs.51job.com/hot/.*html' value = re.findall(rex, http) for i in value: print i try: readpage(i) except: pass def readpage(url): cj = cookielib.MozillaCookieJar() cookie_support = urllib2.HTTPCookieProcessor(cj) opener = urllib2.build_opener(cookie_support) opener.addheaders = [('User-agent','Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0 Iceweasel/38.3.0')] urllib2.install_opener(opener) html = urllib2.urlopen(url,timeout = 2).read() doc = lxml.html.fromstring(html) rex = r'[\w\.-]+@(:[A-Za-z0-9]+\.)+[A-Za-z]+' results = doc.xpath('//div[@class="tmsg inbox"]/div[@class="con_msg"]/div[@class="in"]/p/text()') for i in results: xx = re.compile(rex) for j in xx.findall(i): print j f.write(j+'\n') f.flush() if __name__ == '__main__': city_list = ['zhangjiagang','zhanjiang','zhaoqing','zibo'] for i in city_list: f.write(i+'\n') f.flush() try: read(i) except: pass f.flush() f.close()
本文由职坐标整理并发布,了解更多内容,请关注职坐标编程语言Python频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号