Ich habe eine Textdatei mit einer Liste von URLs von Bildern einer Website. Ich möchte sie in einen Ordner namens Art auf meinem Computer herunterladen.
Ich habe versucht Get Contents of TextEdit Document und dann Extract URLs from Text , aber dann verstehe ich nicht, wie man jede URL analysiert und das Bild speichert, bevor man zur nächsten URL wechselt.
Wie kann ich mehrere Bilder stapelweise von ihren URLs herunterladen?
Nehmen wir für eine Sekunde an, dass sich Ihre Bild-URLs in einer Textdatei befinden, die sich auf Ihrem Desktop befindet ... "Image list.txt"
Nehmen wir an, jede Bild-URL in dieser Datei befindet sich in einer separaten Zeile
Nehmen wir an, dass sich der Ordner „Art“ auf Ihrem Desktop befindet (Ordner für die heruntergeladenen Bilder)
Dieser AppleScript-Code ist alles, was Sie brauchen
set theList to (path to desktop as text) & "Image list.txt"
set artFolder to (path to desktop as text) & "Art"
set artFolder to quoted form of POSIX path of artFolder
set theImages to read alias theList as list using delimiter linefeed -- get the lines of a file as a list
repeat with i from 1 to count of theImages
set thisItem to item i of theImages
do shell script "cd " & artFolder & "; " & "curl -O " & quoted form of thisItem
end repeat
Eigentlich ist hier eine noch bessere Lösung. Speichern Sie den folgenden AppleScript-Code in Script Editor.app als Anwendung. Jetzt haben Sie zwei Möglichkeiten.
Ein Doppelklick auf die App im Finder öffnet einen Dialog, in dem Sie aufgefordert werden, die Textdatei mit den Bild-URLs auszuwählen, und fährt dann mit dem Herunterladen der Bilder fort.
ODER
Sie können die Textdatei mit den Bild-URLs direkt auf das Symbol der App im Finder ziehen, der dann die Bilder in dieser Textdatei verarbeitet und herunterlädt. (AKA Tröpfchen)
on open theFiles
-- Handle the case where the script is launched by dropping
-- a .txt file, containing image URLs, directly onto this app's icon
set artFolder to (path to desktop as text) & "Art"
set artFolder to quoted form of POSIX path of artFolder
set theImages to read alias theFiles as list using delimiter linefeed
repeat with i from 1 to count of theImages
set thisItem to item i of theImages
do shell script "cd " & artFolder & "; " & "curl -O " & quoted form of thisItem
end repeat
end open
on run
-- Handle the case where the script is launched without any dropped files
set theList to (choose file with prompt ¬
"Choose Your Text File Containing Image URLs" of type {"txt"} ¬
default location (path to desktop) ¬
invisibles false ¬
without multiple selections allowed) as text
set artFolder to (path to desktop as text) & "Art"
set artFolder to quoted form of POSIX path of artFolder
set theImages to read alias theList as list using delimiter linefeed
repeat with i from 1 to count of theImages
set thisItem to item i of theImages
do shell script "cd " & artFolder & "; " & "curl -O " & quoted form of thisItem
end repeat
end run
Hier ist ein Bild des Tröpfchens in Aktion ...
curl: (3) [globbing] unmatched brace in column 1
. Nicht sicher, was das heißt. Wie kann ich es reparieren? Der Einfachheit halber habe ich auf meinem Desktop einen Ordner namens Art
und eine Datei namens Image list.txt
mit einer URL pro Zeile erstellt. Vielen Dank im Voraus!Ich gehe davon aus, dass Sie eine Textdatei mit einer URL pro Zeile haben. Das ist wichtig für den folgenden Workflow. Ich gehe auch davon aus, dass Sie reine JPG/PNG-URLs haben, die direkt auf die Bilder verlinken und nicht auf die URL-Seiten von HTML mit Bildern darin.
Ich werde Safari ansprechen, weil die Wahrscheinlichkeit hoch ist, dass der Browser in Ihrem System installiert ist, aber andere Browser sollten auf die gleiche Weise funktionieren.
1 - Öffnen Sie Safari und gehen Sie zu "Einstellungen", "Allgemein" und legen Sie Ihren Standardspeicherort für Dateidownloads auf Ihren ART- Ordner fest:
2 - Öffnen Sie Automator, erstellen Sie einen neuen Workflow und ziehen Sie eine Aktion "AppleScript ausführen":
3 - Fügen Sie den folgenden Code ein:
on run
set the clipboard to {}
tell application "TextEdit" to activate
tell application "System Events"
key code 126 using command down -- go to the start of the doc (command+up)
delay 0.1
key code 124 using {command down, shift down} -- select the first line (commmand+shift+right arrow)
delay 0.1
key code 8 using command down -- copy URL (command+C)
delay 0.1
end tell
repeat while (the clipboard) is not "EXIT"
tell application "Safari" to activate
tell application "System Events"
key code 37 using command down -- Open Location (Command+L)
delay 0.1
key code 9 using command down -- paste URL (Command+V)
delay 0.1
key code 36 -- enter
delay 3 -- three seconds to begin loading the image, adjust if necessary
key code 1 using command down -- Save (command+S)
delay 0.1
key code 36 -- enter
repeat while exists window "Save" of application process "Safari"
delay 0.5 -- wait the save to end
end repeat
end tell
tell application "TextEdit" to activate -- back to textEdit
tell application "System Events"
key code 125 -- go to next line
delay 0.1
key code 123 using command down -- go to the start of the line (command + left key)
delay 0.1
key code 124 using {command down, shift down} -- select the line (commmand+shift+right arrow)
delay 0.1
key code 8 using command down -- copy URL (Command+C)
delay 0.1
end tell
end repeat
end run
4 - Platzieren Sie ein "EXIT" in der letzten Zeile des Dokuments, damit das Programm jetzt, wenn die Arbeit erledigt ist:
5 - Führen Sie den Arbeitsablauf aus
Ich habe es getestet und es funktioniert gut.
Ernie
xargs
undcurl
eine darauf basierende Befehlszeilenlösung sollten funktionieren: stackoverflow.com/questions/9865866/…