[英]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.