python 如何:使用Python和Google查找数百个电子邮件地址

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 如何:使用Python和Google查找数百个电子邮件地址相关的知识,希望对你有一定的参考价值。

#!/usr/bin/python

import sys
import re
import string
import httplib
import urllib2
import re

def StripTags(text):
    finished = 0
    while not finished:
        finished = 1
        start = text.find("<")
        if start >= 0:
            stop = text[start:].find(">")
            if stop >= 0:
                text = text[:start] + text[start+stop+1:]
                finished = 0
    return text

if len(sys.argv) != 2:
        print "\nrsx.py : Find hundreds of e-mail adresses on Google.\n"
        print "\nUsage : ./rsx.py \n"
        print "\nexemple: ./rsx.py gmail.com \n"
        sys.exit(1)

domain_name=sys.argv[1]
d={}
page_counter = 0
try:
    while page_counter <400:
        results = 'http://groups.google.com/groups?q='+str(domain_name)+'&hl=en&lr=&ie=UTF-8&start=' + repr(page_counter) + '&sa=N'
        request = urllib2.Request(results)
        request.add_header('User-Agent','Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)')
        opener = urllib2.build_opener()
        text = opener.open(request).read()
        emails = (re.findall('([\w\.\-]+@'+domain_name+')',StripTags(text)))
        for email in emails:
            d[email]=1
            uniq_emails=d.keys()
        page_counter = page_counter +10
except IOError:
    print "No result found!"+""
page_counter_web=0
try:
    print "\n\n+++++++++++++++++++++++++++++++++++++++++++++++++++++"+""
    print "+ Results:"+""
    print "+++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n"+""

    while page_counter_web >400 :
        results_web = 'http://www.google.com/search?q=%40'+str(domain_name)+'&hl=en&lr=&ie=UTF-8&start=' + repr(page_counter_web) + '&sa=N'
        request_web = urllib2.Request(results_web)
        request_web.add_header('User-Agent','Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)')
        opener_web = urllib2.build_opener()
        text = opener_web.open(request_web).read()
        emails_web = (re.findall('([\w\.\-]+@'+domain_name+')',StripTags(text)))
        for email_web in emails_web:
            d[email_web]=1
            uniq_emails_web=d.keys()
        page_counter_web = page_counter_web +10

except IOError:
    print "No results found!"+""
for uniq_emails_web in d.keys():
    print uniq_emails_web+""

以上是关于python 如何:使用Python和Google查找数百个电子邮件地址的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 Python 运行 Google gsutil

如何使用GAE收听Google表格,然后运行一组python代码?

如何在Google App Engine上建立flex和python代码之间的通信

如何使用 Python 控制 Google Hangouts?

如何在 python 中使用现有的 google chrome 配置文件和 selenium chrome webdriver?

如何将 AJAX 与 Google App Engine (Python) 结合使用