时间:2021-07-01 10:21:17 帮助过:32人阅读
实例代码如下:
import urllib
doc = urllib.urlopen("http://www.python.org").read()
print doc#直接打印出网页
def reporthook(*a):
print a
#将http://www.renren.com网页保存到renre.html中,
#每读取一个块调用一字reporthook函数
urllib.urlretrieve("http://www.renren.com",'renren.html',reporthook)
#将http://www.renren.com网页保存到renre.html中
urllib.urlretrieve("http://www.renren.com",'renren.html')
程序运行结果如下:
..........................网页内容