例一:使用httplib访问某个url然后获取返回的内容:
例二:使用smtplib发送邮件
import
httplib
conn = httplib.HTTPConnection( " www.cnblogs.com " )
conn.request( " GET " , " /coderzh/archive/2008/05/13/1194445.html " )
r = conn.getresponse()
print r.read() # 获取所有内容
conn = httplib.HTTPConnection( " www.cnblogs.com " )
conn.request( " GET " , " /coderzh/archive/2008/05/13/1194445.html " )
r = conn.getresponse()
print r.read() # 获取所有内容
例二:使用smtplib发送邮件
import
smtplib
smtpServer = ' smtp.xxx.com '
fromaddr = ' foo@xxx.com '
toaddrs = ' your@xxx.com '
msg = ' Subject: xxxxxxxxx '
server = smtplib.SMTP(smtpServer)
server.sendmail(fromaddr, toaddrs, msg)
server.quit( )
smtpServer = ' smtp.xxx.com '
fromaddr = ' foo@xxx.com '
toaddrs = ' your@xxx.com '
msg = ' Subject: xxxxxxxxx '
server = smtplib.SMTP(smtpServer)
server.sendmail(fromaddr, toaddrs, msg)
server.quit( )
Python 天天美味系列(总)
Python 天天美味(19) - 时间处理datetime
Python 天天美味(20) - 命令行参数sys.argv
Python 天天美味(21) - httplib,smtplib
Python 天天美味(22) - 拷贝对象(深拷贝deepcopy与浅拷贝copy)
Python 天天美味(23) - enumerate遍历数组
...
本文转自CoderZh博客园博客,原文链接:http://www.cnblogs.com/coderzh/archive/2008/05/17/1201449.html,如需转载请自行联系原作者