Python urllib.urlretrive无法将图像下载到该文件夹 中

问题描述 投票:0回答:1

我想使用python制作instagram照片下载器,我将为我归档所有图像url,然后将其下载到我指定的文件夹中。

我设法创建一个也获取url的文件夹,但是图像似乎并不像下载到该文件夹​​。

下面是代码


   def download_image(self, src, image_filename, folder):
        """
        Creates a folder named after a user to to store the image, then downloads the image to the folder.
        """

        folder_path = 'C:/{}'.format(folder)
        #folder_path = 'C:\\.{}'.format(folder)

        if not os.path.exists(folder_path):
            os.mkdir(folder_path)
            print("folder not create")

        img_filename = 'image_{}.jpg'.format(image_filename)
        print(str(src),"  File Name",str(image_filename)," Folder ",str(folder))
        urllib.request.urlretrieve(src, '{}/{}'.format(folder, img_filename))

输出是这个

# image url
https://instagram.fkul8-1.fna.fbcdn.net/v/t51.2885-15/sh0.08/e35/c120.0.720.720a/s640x640/19534375_479423379059793_7995041966070956032_n.jpg?_nc_ht=instagram.fkul8-1.fna.fbcdn.net&_nc_cat=109&oh=7c8e2f8816f17627424bf38d0267f39b&oe=5E7DFCA1   

# file name is the image name and folder name is kwting3
File Name kwt1  Folder  kwting3
python selenium instagram urllib
1个回答
0
投票
options = webdriver.ChromeOptions() options.add_argument("download.default_directory=C:/Downloads") # specify some other file path here driver = webdriver.Chrome(chrome_options=options)

您将在初始化WebDriver对象的最开始处添加此代码。

© www.soinside.com 2019 - 2024. All rights reserved.