Dump dom of url from command line with safari? The following command will dump the dom for a web page using Google Chrome:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome  --headless --disable-gpu --dump-dom http://example.com

I'm wondering if something similar is possible for Safari.
I can do this with AppleScript but I'd prefer the solution for Safari to be &quot;headless&quot; (see --headless option in command above), so I think an AppleScript will not achieve what I'm looking for.
** UPDATE **
Selenium driver has a headless mode for other browsers. But it doesn't look like there is such a mode for safari: https://stackoverflow.com/a/58314435
I’m fairly confident Safari isn’t amenable to scraping, so use Chrome or Firefox for that on macOS if you need a browser to be scriptable.
However, swift and python are exceptionally good at this by calling code directly via NSURL or equivalent as well as using the NSURLSessiond daemon and working with the OS directly and not even needing Safari.

https://stackoverflow.com/questions/41517065/web-scraping-in-apple-swift-3
How to know what nsurlsessiond is downloading

Of course you have to learn some new language and API/SDK for this to pay off. The pay off can be huge if you have a command line tool that does all the heavy lifting far more efficiently than Chrome or Safari can.