使用python下载文件 分类: python python下载 2013-06-22 16:58 277人阅读 评论(0) 收藏

#使用urllib2模块下载文件:

方法一:

#! /usr/bin/env python

#coding=utf-8

import urllib2

import os


print os.getcwd() #返回当前的工作目录


response = urllib2.Request('http://picm.photophoto.cn/015/037/003/0370030333.jpg');
rs = urllib2.urlopen(response)

f = open("pic.jpg",'wb')


f.write(rs.read());
f.close();


方法二:

import os
import urllib2

print os.getcwd()

rs = urllib2.urlopen("http://picm.photophoto.cn/015/037/003/0370030333.jpg")

with open('tag.jpg','wb') as f:
    f.write(rs.read())


原文地址:https://www.cnblogs.com/think1988/p/4628152.html