urllib2下载文件

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#!/usr/bin/python
# coding=utf8

import os
import urllib2

dir = "/home/saint/demo/"
url = "http://img0.bdstatic.com/img/image/shouye/xinshouye/mingxing123.jpg"
file_name = url.split("/")[-1]

# 修改目录
os.chdir(dir)
file = urllib2.urlopen(url).read()

open(file_name, "wb").write(file)

print("OK")