下载网页,发邮件到邮箱
来源:互联网 发布:霍先生加的安之知TXT 编辑:程序博客网 时间:2024/04/28 10:25
<pre name="code" class="python"># -*- coding: utf-8 -*-import urllib2import osimport datetimeimport smtplibfrom email.mime.text import MIMETextmailto_list=["*******@qq.com"]#####################mail_host="smtp.126.com"mail_user="name"mail_pass="****"mail_postfix="126.com"######################def get_httpcode(url,id): headers={'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'} try: response=urllib2.Request(url,headers=headers) res=urllib2.urlopen(response).code html=urllib2.urlopen(response).read() if res == 200: print "Begin to download the page " if os.path.exists('D:\\Program\\html\\'+id+'.html')==True: print 'The file is exist' else: print 'Download the page now' file=open('D:\\Program\\html\\'+id+'.html','w') file.write(html) file.close() send_mail(mailto_list,"subject",url) print 'Download complete' except urllib2.HTTPError as e: if e.code==404: print 'Error 404' else : print e.code def send_mail(to_list,sub,content): me=mail_user+"<"+mail_user+"@"+mail_postfix+">" msg = MIMEText(content) msg['Subject'] = sub msg['From'] = me msg['To'] = ";".join(to_list) try: s = smtplib.SMTP() s.connect(mail_host) s.login(mail_user,mail_pass) s.sendmail(me, to_list, msg.as_string()) s.close() return True except Exception, e: print str(e) return False if __name__=='__main__': #num=38727380 starttime=datetime.datetime.now() headers={'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'} for i in range(38727389,38830000): url='http://blog.csdn.net/****/article/details/' + str(i) print url list1=url[-8:] get_httpcode(url,list1) endtime=datetime.datetime.now() usetime=endtime-starttime print 'The Program cost '+str(usetime)
0 0
- 下载网页,发邮件到邮箱
- linux如何发邮件到外部邮箱
- linux如何发邮件到外部邮箱
- 邮箱发邮件
- QQ邮箱发邮件
- qq邮箱发邮件
- mysql 自动备份发邮件 到指定邮箱
- Linux 通过sendmail 发邮件到外部邮箱
- 提交订单系统自动发邮件到收件人邮箱
- 不登录邮箱发邮件
- C# QQ邮箱发邮件
- 邮箱发邮件代码示例
- 实现用户在网页中给我的QQ邮箱发邮件
- 将激活信息 自动发邮件到你的邮箱中
- 如何利用SAP邮箱发邮件
- linux自动登录邮箱发邮件
- 如何利用SAP邮箱发邮件
- ASP.Net邮箱发邮件源码
- jordan femme after the registration of the school
- PHP 连接MySQL的几种方法
- update 语句更新慢如何优化
- sdafgvs
- OpenGL ES2.0 的三种变量类型(uniform,attribute和varying)
- 下载网页,发邮件到邮箱
- poj——Human Gene Functions
- nginx反向代理,负载均衡,缓存的配置文件,带注释
- 【博弈论】从博弈的角度看“罗质翔”
- WPF 读取xml
- Java多线程:线程的调度-优先级
- Android 的 init.rc 文件简介
- 黑马程序员—(iOS开发)iOS了解---(七)
- Contiki:RDC &CoAP