import urllib
def downURL(url,filename):
try:
fp=urllib.urlopen(url)
except:
print('download error')
return 0
op=open(filename,'wb')
while 1:
s=fp.read()
if not s:
break
op.write(s)
fp.close()
op.close()
return 1
def downURL(url,filename):
try:
fp=urllib.urlopen(url)
except:
print('download error')
return 0
op=open(filename,'wb')
while 1:
s=fp.read()
if not s:
break
op.write(s)
fp.close()
op.close()
return 1
downURL("http://www.baidu.com","D:\\code\\url.txt")
原文链接: http://blog.youkuaiyun.com/mypc2010/article/details/8223900