使用httplib访问某个url然后获取返回的内容和使用smtplib发送邮件的脚本实例代码

例一:使用httplib访问某个url然后获取返回的内容:

Python httplib,smtplib使用方法详解-LMLPHPimport httplib
Python httplib,smtplib使用方法详解-LMLPHP
Python httplib,smtplib使用方法详解-LMLPHPconn
=httplib.HTTPConnection("www.cnblogs.com")
Python httplib,smtplib使用方法详解-LMLPHPconn.request(
"GET", "/coderzh/archive/2008/05/13/1194445.html")
Python httplib,smtplib使用方法详解-LMLPHPr
=conn.getresponse()
Python httplib,smtplib使用方法详解-LMLPHP
print r.read() #获取所有内容


例二:使用smtplib发送邮件

Python httplib,smtplib使用方法详解-LMLPHPimport smtplib
Python httplib,smtplib使用方法详解-LMLPHPsmtpServer
= 'smtp.xxx.com'
Python httplib,smtplib使用方法详解-LMLPHPfromaddr
= '[email protected]'
Python httplib,smtplib使用方法详解-LMLPHPtoaddrs
= '[email protected]'
Python httplib,smtplib使用方法详解-LMLPHPmsg
= 'Subject: xxxxxxxxx'
Python httplib,smtplib使用方法详解-LMLPHPserver
= smtplib.SMTP(smtpServer)
Python httplib,smtplib使用方法详解-LMLPHPserver.sendmail(fromaddr, toaddrs, msg)
Python httplib,smtplib使用方法详解-LMLPHPserver.quit( )

以上就是Python httplib,smtplib使用方法详解的详细内容,更多请关注Work网其它相关文章!

09-19 06:16