简体   繁体   English

从 CSV 中的 Urls 下载图像到本地文件夹 Python 中的文件

[英]Download Images to Local Folder from Urls in CSV file in Python

I made the program to get the Images from the Urls in the CSV file and want to download it in the Local Folder in Python but the program showing the below error我制作了从 CSV 文件中的 Urls 获取图像的程序,并想将其下载到 Python 中的本地文件夹中,但程序显示以下错误

"TypeError: cannot use a string pattern on a bytes-like object" “TypeError:不能在类似字节的对象上使用字符串模式”

Please check the Code in below请检查下面的代码

import pandas as pd
import urllib.request 


def url_to_jpg(i, url , File_Path):
    filename = 'image_{}.jpg'.format(i)
    full_path = '{}{}'.format(File_Path, filename)
    urllib.request.urlretrieve(url, full_path)
    print('{} saved.'.format(filename))
    return None


FileName = "C:/Users/IT City/Desktop/Kwiat-USA/KavantaCSV.csv"
File_Path = "C:/Users/IT City/Desktop/Kwiat-USA/images"

urls = pd.read_csv(FileName)

for i , url in enumerate(urls.values):
    url_to_jpg(i, url , File_Path)

Need your Immediate help.需要你的即时帮助。 Help will be highly Appreciated.帮助将不胜感激。

Thank You谢谢你

Maybe you have to decode it?也许你必须解码它? -or you can simply use the requests library. - 或者您可以简单地使用请求库。

r = requests.get(url) 
f = open(filename, "wb+")
f.write(r.content)
f.close()

The url being passed to urlretrieve is an array.传递给 urlretrieve 的 url 是一个数组。 the urls.values gives a 2d-array. urls.values 给出了一个二维数组。

it always helps if the stack trace is also posted.如果堆栈跟踪也被发布,它总是有帮助的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 url 列表中抓取图像并将其下载到本地文件夹? - How to I scrape images from a list of urls and download it to local folder? 如何从 csv 文件中的列中的多个 url 下载图像 - how to download images from multiple urls from a column in a csv file 如何使用 url 从 csv 文件下载/保存图像到我本地 Windows 机器上的特定创建文件夹中? - How to download/save images from a csv file using url into specific created folder on my local Windows Machine? Python组织网址的CSV,每个网址分割线,从网址下载图像 - Python organize CSV of urls, split line per url, download images from urls 从本地文件夹下载文件 - Download file from local folder 从Google图片搜索下载许多图像并将其保存到本地文件夹(Python) - Download and SAVE MANY Images from google Image search to a LOCAL FOLDER (Python) 如何将图像从列表下载到 Python 中的文件夹 - How to download images from a list to a folder in Python python 2.7-如何将图像从CSV文件中的URL列表保存到目录 - python 2.7 - How do I save images to a directory from a list of URLs in a CSV file 从CSV文件中的网址中检索数据-Python - Retrieving data from urls in csv file - Python 如何从 python 中的 url 列表中异步下载图像? - How can i asyncronously download images from a list of urls in python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM