Tengo un archivo de texto con una lista de URL de imágenes de un sitio web. Me gustaría descargarlos a una carpeta llamada Arte en mi computadora.
Intenté Obtener el contenido del documento TextEdit y luego Extraer las URL del texto , pero luego no entiendo cómo analizar cada URL y guardar la imagen antes de pasar a la siguiente URL.
¿Cómo puedo descargar por lotes varias imágenes desde sus URL?
Supongamos por un segundo que las URL de su imagen están en un archivo de texto ubicado en su escritorio... "Lista de imágenes.txt"
Supongamos que cada URL de imagen en ese archivo está en una línea separada
Supongamos que la carpeta "Arte" se encuentra en su escritorio (carpeta para las imágenes descargadas)
Este código AppleScript es todo lo que necesitas
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
En realidad, aquí hay una solución aún mejor. Guarde este siguiente código AppleScript en Script Editor.app como una aplicación. Ahora tendrás dos opciones.
Al hacer doble clic en la aplicación en Finder, se abrirá un cuadro de diálogo que le pedirá que elija el archivo de texto que contiene las URL de las imágenes y luego procederá a descargar las imágenes.
O
Puede arrastrar el archivo de texto que contiene las URL de las imágenes directamente al ícono de la aplicación, en Finder, que luego continuará, procesará y descargará las imágenes en ese archivo de texto. (también conocido como gota)
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
Aquí hay una imagen de la gota en acción...
curl: (3) [globbing] unmatched brace in column 1
. No estoy seguro de lo que eso significa. ¿Cómo puedo arreglarlo? En aras de la simplicidad, creé una carpeta en mi escritorio con un nombre Art
y un archivo Image list.txt
con un URL por línea. ¡Gracias de antemano!Supongo que tiene un archivo de texto con una URL por línea. Eso es importante para el siguiente flujo de trabajo. También asumo que tiene URL jpg/png puras, con enlaces directos a las imágenes y no a las páginas URL de html con imágenes dentro.
Me referiré a Safari porque hay muchas posibilidades de que el navegador esté instalado en su sistema, pero otros navegadores deberían funcionar de la misma manera.
1 - Abra Safari y vaya a preferencias, general, y configure su ubicación de descarga de archivos predeterminada en su carpeta ART :
2 - Abra Automator, cree un nuevo flujo de trabajo y arrastre una acción Ejecutar AppleScript:
3 - Pega el siguiente código:
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 - Coloque un "SALIR" en la última línea del documento para que el programa ahora cuando termine el trabajo:
5 - Ejecute el flujo de trabajo
Lo he probado y funciona bien.
ernie
xargs
ycurl
la solución de línea de comandos basada deberían funcionar: stackoverflow.com/questions/9865866/…