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

 

相关文章:

  • 2021-10-13
  • 2022-12-23
  • 2021-12-24
  • 2022-01-11
  • 2021-05-15
猜你喜欢
  • 2021-11-24
  • 2018-05-03
  • 2021-10-01
  • 2021-05-03
  • 2021-04-15
  • 2021-12-12
  • 2021-12-01
相关资源
相似解决方案