etaoin

john 2023-06-09T19:30:30.722269Z

Hello

john 2023-06-09T19:30:54.659939Z

Big fan of etaoin here, thanks for this lib

john 2023-06-09T19:31:04.042849Z

I'm just tring to figure out how to download images

john 2023-06-09T19:32:27.763789Z

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

john 2023-06-09T19:33:37.037139Z

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

john 2023-06-09T19:33:41.084969Z

But no mas

lread 2023-06-09T19:51:04.274799Z

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?

john 2023-06-09T19:55:35.454189Z

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

john 2023-06-09T19:56:23.770679Z

Thanks for the quick response!

lread 2023-06-09T19:57:36.124169Z

My pleasure, if you remain stuck, happy to try and help.

john 2023-06-09T19:58:03.347419Z

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

lread 2023-06-09T20:04:52.955329Z

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.

lread 2023-06-10T04:20:41.888159Z

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.

👍 1
lread 2023-06-09T20:06:32.785849Z

If you don't give it a whirl, I can do so sometime later.

john 2023-06-09T21:58:49.640509Z

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)))

john 2023-06-09T21:59:04.838539Z

Then just (save @d "some/file/on-this-domain/somwhere.jpg" "local-name.jpg")

john 2023-06-09T21:59:40.623809Z

Very useful in a pinch

john 2023-06-09T22:00:12.735989Z

Not sure if it works cross domain

john 2023-06-09T22:02:07.359279Z

Feel free to add that to some utility fn somewhere if you like it or can improve on it and find it useful

lread 2023-06-09T22:51:46.541619Z

Interesting, thanks for sharing what you came up with!

john 2023-06-09T23:03:56.753789Z

Still have to test it out but yeah super relieved I don't have to get curl working here

lread 2023-06-10T04:11:56.302539Z

@john were you spawning out? There are lotsa wee Clojure HTTP clients, for example: https://github.com/babashka/http-client

john 2023-06-10T05:19:54.770999Z

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.

👍 1