[英]How to I scrape images from a list of urls and download it to local folder?
[英]How do I bulk download images (70k) from urls with a restriction on the simultaneous downloads?
我有點不知所措。 我有一個包含這些列的 csv 文件:名稱 - 圖片 url 我想將 70k 圖像批量下載到一個文件夾中,使用第一列中的名稱重命名圖像,如果每個名稱有多個,則對其進行編號。 有些是jpeg,有些是png。
我猜我需要使用 Pandas 從 csv 中獲取數據,但我不知道如何在不同時啟動所有下載的情況下制作下載/重命名部分,這肯定會使我的計算機崩潰(它確實,我什至沒有生氣)。 預先感謝您對此的任何了解。
嘗試分批下載 500 張圖像...然后休眠 1 秒鍾並循環播放.... 相當耗時...但肯定會觸發方法....對於編碼參考,您可以探索像 urllib 這樣的包(用於下載) 並在您下載文件后立即使用 os.rename() 更改名稱....因為您已經知道該 csv 文件使用 Pandas...
我是一個編碼白痴。 . . 所以用一小撮鹽吃這個。
我需要在(第 1 列帶有 URL,第 2 列帶有文件名)中獲取一個 CSV 並將其放入代碼運行目錄中的現有文件夾中。
對我來說就像一種魅力。 也許這里有幫助
#import Libraries
import csv
import urllib.request
# Function to download file from URL to a SPECIFIED FOLDER with a SPECIFIED NAME
def dl_jpg(url, file_path, file_name):
full_path = file_path + file_name + '.jpg'
urllib.request.urlretrieve(url, full_path)
# Get CSV File-name and Folder to store images from the user
file_name = input('Please enter filename: ')
folder_name = input('Please enter a folder name: ')
# Open SPECIFIED CSV and iterate through the URL on each line and call the Download function for each Line and filename.
with open(file_name + '.csv','r') as csv_file:
csv_reader = csv.reader(csv_file)
next(csv_reader)
for line in csv_reader:
print(line[0])
dl_jpg(line[0],folder_name +'/', line[1])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.