首页 编程教程正文

python爬取51job中hr的邮箱

piaodoo 编程教程 2020-02-02 12:37:53 1126 0 python教程

这篇文章主要为大家详细介绍了python爬取51job中hr的邮箱的相关资料,需要的朋友可以参考下

本文实例为大家分享了python爬取51job中hr的邮箱具体代码,供大家参考,具体内容如下

#encoding=utf8
import urllib2
import cookielib
import re
import lxml.html
from _ast import TryExcept
from warnings import catch_warnings

f = open('/root/Desktop/51-01.txt','a+')

def read(city):
  url = 'http://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 = 'http://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()

city_list大家自己整理一下,只能帮你们到这里了,谢谢大家的阅读,继续关注脚本之家更多精彩内容。

版权声明:

本站所有资源均为站长或网友整理自互联网或站长购买自互联网,站长无法分辨资源版权出自何处,所以不承担任何版权以及其他问题带来的法律责任,如有侵权或者其他问题请联系站长删除!站长QQ754403226 谢谢。

有关影视版权:本站只供百度云网盘资源,版权均属于影片公司所有,请在下载后24小时删除,切勿用于商业用途。本站所有资源信息均从互联网搜索而来,本站不对显示的内容承担责任,如您认为本站页面信息侵犯了您的权益,请附上版权证明邮件告知【754403226@qq.com】,在收到邮件后72小时内删除。本文链接:https://www.piaodoo.com/2728.html

搜索