import requests  
import os 
def gethtml(url):   
    try:   
        path = "/Users/new/Desktop/汇总/爬虫/"
        path = path+url.split("/")[-1]
        r = requests.get(url)
        r.raise_for_status() #状态 
        r.encoding=r.apparent_encoding #编码
        with open(path,'wb') as f: 
            f.write(r.content) 
            f.close() 
    except: 
        return "异常"
if __name__== "__main__": 
    url = "http://image.nationalgeographic.com.cn/2017/0211/20170211061910157.jpg" 
    gethtml(url)