可用于获取百度贴吧的帖子中的Email地址的Python脚本
2016-07-28 14:37
477 查看
# _*_ coding:utf-8 _*_
import urllib,urllib2
import re
import time
print('该脚本可用于获取百度贴吧的帖子中的Email地址,获取后保存在D:\Email.txt中,可能需要权限创建这个文件,如可能请以管理员身份运行')
print('网页URL中含有#的有可能失败(#是python的注释标志)')
myUrl=raw_input('请输入网页URL:')
minIndex=int(input('请输入起始页码:'))
maxIndex=int(input('请输入终止页码:'))
firstPattern=re.compile(r'(\?pn=\d+)$')
myUrl=re.sub(firstPattern,'',myUrl)
try:
fp=open(r'D:\Email.txt','a+')
print(time.strftime('%Y-%m-%d-%H-%M-%S:',time.localtime(time.time())))
fp.write(time.strftime('\n%Y-%m-%d-%H-%M-%S:\n',time.localtime(time.time())))
for i in range(minIndex,maxIndex+1):
index=myUrl.rfind(r'?pn=')
if index==-1:
myUrl=myUrl+r'?pn='+str(i)
else:
myUrl=re.sub(firstPattern,r'?pn='+str(i),myUrl)
print(myUrl)
#rep=urllib.Request(myUrl)
rep=urllib2.Request(myUrl)
# rep=urllib.urlopen(myUrl)
response=urllib2.urlopen(rep)
myPage=response.read()
myPage=myPage.decode('utf-8')
myPage=myPage.replace(r'\r\n','')
pattern=re.compile(r'([a-zA-Z0-9]+@[a-zA-Z0-9]+\.?[a-zA-Z0-9]+\.+[a-zA-Z0-9]+)')
result=pattern.findall(myPage)
if result is not None:
for email in result:
print(email)
fp.write(email+';')
else:
print("not found")
fp.close()
print('Suceed!!!')
except Exception as e:
print(e.message)
fp.close()
import urllib,urllib2
import re
import time
print('该脚本可用于获取百度贴吧的帖子中的Email地址,获取后保存在D:\Email.txt中,可能需要权限创建这个文件,如可能请以管理员身份运行')
print('网页URL中含有#的有可能失败(#是python的注释标志)')
myUrl=raw_input('请输入网页URL:')
minIndex=int(input('请输入起始页码:'))
maxIndex=int(input('请输入终止页码:'))
firstPattern=re.compile(r'(\?pn=\d+)$')
myUrl=re.sub(firstPattern,'',myUrl)
try:
fp=open(r'D:\Email.txt','a+')
print(time.strftime('%Y-%m-%d-%H-%M-%S:',time.localtime(time.time())))
fp.write(time.strftime('\n%Y-%m-%d-%H-%M-%S:\n',time.localtime(time.time())))
for i in range(minIndex,maxIndex+1):
index=myUrl.rfind(r'?pn=')
if index==-1:
myUrl=myUrl+r'?pn='+str(i)
else:
myUrl=re.sub(firstPattern,r'?pn='+str(i),myUrl)
print(myUrl)
#rep=urllib.Request(myUrl)
rep=urllib2.Request(myUrl)
# rep=urllib.urlopen(myUrl)
response=urllib2.urlopen(rep)
myPage=response.read()
myPage=myPage.decode('utf-8')
myPage=myPage.replace(r'\r\n','')
pattern=re.compile(r'([a-zA-Z0-9]+@[a-zA-Z0-9]+\.?[a-zA-Z0-9]+\.+[a-zA-Z0-9]+)')
result=pattern.findall(myPage)
if result is not None:
for email in result:
print(email)
fp.write(email+';')
else:
print("not found")
fp.close()
print('Suceed!!!')
except Exception as e:
print(e.message)
fp.close()
相关文章推荐
- Python间各种进制之间的转换
- Python随机生成数据后插入到PostgreSQL
- Python: sort,sorted,OrderedDict的用法
- 阿里音乐流行趋势预测大赛—浅尝辄止(一)
- 浅谈 Python 程序和 C 程序的整合
- Python 正则表达式 (附调试工具)
- python学习笔记系列----(一)python简介
- Python学习笔记
- python基础语法(1)
- numpy函数:tile函数用法
- 一句话证明你开始接触Python
- Python学习笔记(零)-- Python简介
- Python动态加载
- Python import 功能(进阶篇)
- 如何在sublime text 3中关联python
- ndarray 矢量化(vectorization)
- ndarray 数据类型 —— dtype
- python __init__.py __name__ __doc__ __file__ argv[0] 浅析
- python命名中下划线的含义
- 80个Python经典资料(教程+源码+工具)汇总