您的位置:首页 > 编程语言 > Python开发

python最简单的爬取邮箱地址

2015-06-18 15:48 676 查看
http://www.jb51.net/article/57161.htm
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import re
import sys

def getIPAddFromFile(fobj):
    regex = re.compile(r'\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b', re.IGNORECASE)
    ipadds = re.findall(regex, fobj)
    print ipadds
    return ipadds

def getPhoneNumFromFile(fobj):
    regex = re.compile(r'1\d{10}', re.IGNORECASE)
    phonenums = re.findall(regex, fobj)
    print phonenums
    return phonenums

def getMailAddFromFile(fobj):
    regex = re.compile(r"\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b", re.IGNORECASE)
    mails = re.findall(regex, fobj)
    print mails
    return mails

def getUrlFromFile(fobj):
    regex = re.compile(r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+", re.IGNORECASE)
    urls = regex.findall(fobj)
    print urls
    return urls

def main(FilefilePath):
    fobj = open(FilefilePath, 'rb').read()
    urllist = getUrlFromFile(fobj)
    mailList = getMailAddFromFile(fobj)
    phoneNum = getPhoneNumFromFile(fobj)
    ipaddlist = getIPAddFromFile(fobj)

if __name__ == '__main__':
    main(sys.argv[1])
</pre><pre name="code" class="python">
</pre><pre name="code" class="python">
# -*- coding: utf-8 -*- 
import re
import urllib

def getHtml(url):
    page = urllib.urlopen(url)
    html = page.read()
    return html

def getImg(html):
    reg = r'src="(.+?\.jpg)" pic_ext'
    #p=re.compile('[^\._-][\w\.-]+@(?:[A-Za-z0-9]+\.)+[A-Za-z]+$|^0\d{2,3}\d{7,8}$|^1[358]\d{9}$|^147\d{8}')
    regex = re.compile(r"\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b", re.IGNORECASE)
    
    
    imgre = re.compile(regex)
    imglist = re.findall(regex,html)
    print imglist
    return imglist   
    #x=0
    #for imgurl in imglist:
        #urllib.urlretrieve(imgurl,'%s.jpg' % x) 
        #x=x+1
   
html = getHtml("http://tieba.baidu.com/p/3827945043")
print getImg(html)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: