Home > Backend Development > Python Tutorial > Python httplib,smtplib使用方法

Python httplib,smtplib使用方法

WBOY
Release: 2016-06-16 08:47:33
Original
1119 people have browsed it

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

import httplib

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( )
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template