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

16 Replies, 1169 Views

Hey! I’ve actually done something similar before. You’re on the right track with using JavaScript via AppleScript to grab image URLs from the DOM. Here’s a quick snippet to get you started:

```applescript
tell application "Safari"
do JavaScript "document.querySelectorAll('img').forEach(img => console.log(img.src));" in document 1
end tell
```

This logs all image URLs to the console. You can then use AppleScript to save them. If you need help with the download part, lmk!

Also, check out this guide on combining AppleScript and JavaScript for DOM manipulation: [link]. Super helpful for stuff like this.

Messages In This Thread



Users browsing this thread: 1 Guest(s)