How can I use AppleScript and HTML DOM to download images from a webpage?

16 Replies, 1174 Views

Hmm, I’ve never tried AppleScript HTML DOM download images, but I’ve used Python for similar tasks. If you’re open to switching, `requests` and `BeautifulSoup` make this super easy.

That said, if you’re committed to AppleScript, try this:

```applescript
tell application "Safari"
set imgList to do JavaScript "Array.from(document.querySelectorAll('img')).map(img => img.src);" in document 1
end tell
```

Then, loop through `imgList` and use `do shell script` to download each image.

Messages In This Thread



Users browsing this thread: 1 Guest(s)