python 下载 JPG 图片

Python2 的 urllib 与 urllib2 下载图片后,显示无法正常打开。原因可能为,默认 post 方式下载,而图片应该为 get 方式下载。使用如下代码,问题解决。


requests安装: pip install requests

import requests

# 下载图片
def dowloadPic(imageUrl,filePath):
    r = requests.get(imageUrl)
    with open(filePath, "wb") as code:
        code.write(r.content)

url = 'http://test.com/images/1803_android.jpg'
filePath = "E://pics/1803.jpg"
dowloadPic(url,filePath)

 
  

你可能感兴趣的:(python)