python爬取51job中hr的邮箱

yipeiwu_com5年前Python爬虫

本文实例为大家分享了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大家自己整理一下,只能帮你们到这里了,谢谢大家的阅读,继续关注【听图阁-专注于Python设计】更多精彩内容。

相关文章

深入理解Python爬虫代理池服务

深入理解Python爬虫代理池服务

在公司做分布式深网爬虫,搭建了一套稳定的代理池服务,为上千个爬虫提供有效的代理,保证各个爬虫拿到的都是对应网站有效的代理IP,从而保证爬虫快速稳定的运行,当然在公司做的东西不能开源出来。...

Python3爬虫学习之爬虫利器Beautiful Soup用法分析

Python3爬虫学习之爬虫利器Beautiful Soup用法分析

本文实例讲述了Python3爬虫学习之爬虫利器Beautiful Soup用法。分享给大家供大家参考,具体如下: 爬虫利器Beautiful Soup 前面一篇说到通过urllib.re...

python爬取足球直播吧五大联赛积分榜

本文实例为大家分享了python爬取足球联赛积分榜的具体代码,供大家参考,具体内容如下 使用BeautifulSoup4解析爬取足球直播吧五大联赛积分榜信息; #! /usr/bi...

解决python爬虫中有中文的url问题

解决python爬虫中有中文的url问题

如果URL中存在中文,而你却不对它做任何处理,他不会达到你所想的那样,因此我们需要将中文部分进行处理,要用到urllib.parse模块中的quote将中文转化成URL所需的编码,url...

基于Python实现的百度贴吧网络爬虫实例

基于Python实现的百度贴吧网络爬虫实例

本文实例讲述了基于Python实现的百度贴吧网络爬虫。分享给大家供大家参考。具体如下: 完整实例代码点击此处本站下载。 项目内容: 用Python写的百度贴吧的网络爬虫。 使用方法: 新...