Hello
Big fan of etaoin here, thanks for this lib
I'm just tring to figure out how to download images
I'm using Chrome. I've specificied a download location (a folder in the project dir ./dls/) but when going to (e/go @d goog-logo-img-url), for instance, it just opens it in the tab
My understanding from the docs is that chrome doesn't care about what's in the :prefs key wrt downloads, though I have tried various things there that I've seen related to Firefox prefs in the docs
But no mas
Hiya @john! Yes, Etaoin will tell the webdriver to open goog-logo-img-url in the browser. The browser should behave the same way as if you had pasted that same URL into the address bar of your browser and hit return. Two ideas for you:
1. if the image requires no authentication, do a simple HTTP get on it (outside of etaoin)
2. or maybe https://cljdoc.org/d/etaoin/etaoin/1.0.40/doc/user-guide#_capturing_screenshots might work for your use case?
Would either of those work for you?
Yeah, neither of those work trivially. But both can be massaged. I might just be missing cookies in the curl call. I'll look into it. I'm starting to understand etaoin's data model now, it's like a cljs repl, so get-s are being serialized back to the JVM
Thanks for the quick response!
My pleasure, if you remain stuck, happy to try and help.
And I can get the context menu to pop up, but I just can't click the menu items in the context menu! lol so close
Oh ya, you just want to right click and save image as... or something. Robot do my bidding, dammit! I've not tried it for non-html, but I wonder what https://cljdoc.org/d/etaoin/etaoin/1.0.40/api/etaoin.api?q=source#get-source would do for an image.
Ya @john I tried this on Chrome and Firefox and they both returned HTML for me. Probably the HTML the browser is using to display the image.
If you don't give it a whirl, I can do so sometime later.
This works:
(defn save [driver get-url save-str]
(let [save-js (str "function saveAs() {
const a = document.createElement(\"a\");
fetch(\"" get-url "\")
.then(function(response) {
return response.blob();
})
.then(function(blob) {
const url = window.URL.createObjectURL(blob);
a.href = url;
a.download = \"" save-str "\";
a.click();
window.URL.revokeObjectURL(url);
});};
saveAs();")]
(e/js-execute driver save-js)))Then just (save @d "some/file/on-this-domain/somwhere.jpg" "local-name.jpg")
Very useful in a pinch
Not sure if it works cross domain
Feel free to add that to some utility fn somewhere if you like it or can improve on it and find it useful
Interesting, thanks for sharing what you came up with!
Still have to test it out but yeah super relieved I don't have to get curl working here
@john were you spawning out? There are lotsa wee Clojure HTTP clients, for example: https://github.com/babashka/http-client
The site I'm working with is real finnicky. Even with agent strings and cookies, it didn't want to talk to curl. Screenshot is sufficient for my purposes.