python reptile notes (c) requests module depth - crawling picture of network and storage

1. Network picture crawling

import os 
import requests

root = ".//"
url = "https://img2018.cnblogs.com/i-beta/817161/202001/817161-20200116224428592-123074215.png"
path = root + url.split('/')[-1]

try:
    if not os.path.exists(root):
        os.mkdir(root)
    if not os.path.exists(path):
        r = requests.get(url)
        print(r.status_code)
        with open(path, "wb") AS f: 
            f.write (r.content) 
            f.close () 
            Print ( " File saved successfully " )
     the else :
         Print ( " file already exists " ) 
        
the except :
     Print ( " extract identification " )

Guess you like

Origin www.cnblogs.com/douzujun/p/12216149.html