用Python写个柯南的壁纸图片源代码
```python
# import required libraries
import urllib.request
import os
# download images from the web
def dwnld_img(url, file_name):
full_path = file_name + '.jpg' # create a new path for the image to be downloaded as
urllib.request.urlretrieve(url, full_path) # download and save the image at the given path
# main function that downloads Conan wallpapers from internet
def main():
# Conan Wallpaper Urls list
conan_wallpaper = ['https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/9d7e1b0e-d7f3-4ec5-b818-f2530db6fb1a/d9i2sjg-8560cd81-3ab6-4b99-841e-ce45dd0fe2cc.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7InBhdGgiOiJcL2ZcLzlkN2UxYjBlLWQ3ZjMtNGVjNS1iODE4LWYyNTMwZGI2ZmIxYVwvZDlpMnNqZy04NTYwY2Q4MS0zYWI2LTRiOS05ODQxLWNlNDVkZDBmZTJjYy5qcGciLCJwdWJsaWNfaGFzaCI6ImFhOWRkOGE3MDU3ODBhOTViNDhmMTdiMTdjMWRlMDFlOWEifV1dLCJhdWQiOlsidXJuOnNlcnZpY2U6aW1hZ2Uub3BlcmF0aW9ucyJdfQ.C8SOhKrPrHEmKPvErpEWoMeTnEdEuPKCn7CvAqRmspo', 'https://images6.alphacoders.com/102/thumb1920/102238.png', 'https://www.itl.cat/pngfile/big/91-916052_detectiveconanwallpaperiphonecaseclosedwallpaperiphoneforandroidconanedogawaandranmoriyawallpapersdesktopbackgrounds1920x1280pxjpgconanedogawaiphonewallpapersfreeforphonebackgrounds']
# create a directory to store all wallpapers if it does not exist already
if not os.path.exists('ConanWallpapers'): # check if directory exists or not
os .mkdir('ConanWallpapers') # make a directory named ConanWallapapers to store images in it
print("Directory Created!") # print this message after creating directory successfully
for i, wallpaper in enumerate(conan_wallpaper): # loop through all the links one by one and download them using dwnldimg() function
print("Downloading Image: {}".format(str(i+1))) # print this message while downloading each image
dwnld_img(wallpaper, 'ConanWallpapers\image'+str(int(time()))) # call dwnldimg() function here with given parameters
else: # else part of if condition starts here print("Directory already exists!") # prints this message when directory already exists print("All Images Downloaded Successfully") ## prints this message after downloading all images successfully return True ## returns True after successful execution of program return False ## returns False when any error occurs during execution of program ## end of main() function definition ## calling main() function to start downloading images from web main() ## end of program! ```
免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。