python笔记1
1.文件下载
方法一: import urllib import urllib2 import requests print "downloading with urllib" url = 'https://zhidao.baidu.com/question/1449298459673795180.html' print "downloading with urllib" urllib.urlretrieve(url, "demo.html") 方法二: import urllib2 print "downloading with urllib2" url = 'https://zhidao.baidu.com/question/1449298459673795180.html' f = urllib2.urlopen(url) data = f.read() with open("demo2.html", "wb") as code: code.write(data) 方法三: import requests print "downloading with requests" url = 'https://zhidao.baidu.com/question/1449298459673795180.html' r = requests.get(url) with open("demo3.html", "wb") as code: code.write(r.content)
我用的VS2015 需要安装requests引用 我用的“easy_install requests”
-------此处无银三百两------