发布于 2016-05-26 12:05:31 | 200 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的Python入门,程序狗速度看过来!

Python编程语言

Python 是一种面向对象、解释型计算机程序设计语言,由Guido van Rossum于1989年底发明,第一个公开发行版发行于1991年。Python语法简洁而清晰,具有丰富和强大的类库。它常被昵称为胶水语言,它能够把用其他语言制作的各种模块(尤其是C/C++)很轻松地联结在一起。


这篇文章主要为大家详细介绍了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大家自己整理一下,只能帮你们到这里了,谢谢大家的阅读,继续关注phperz更多精彩内容。



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务