Fork me on GitHub
#etaoin
<
2023-06-09
>
john19:06:54

Big fan of etaoin here, thanks for this lib

john19:06:04

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

john19:06:27

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

john19:06:37

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

john19:06:41

But no mas

lread19:06:04

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?

john19:06:35

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

john19:06:23

Thanks for the quick response!

lread19:06:36

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

john19:06:03

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

lread20:06:52

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.

lread04:06:41

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.

👍 2
lread20:06:32

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

john21:06:49

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

john21:06:04

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

john21:06:40

Very useful in a pinch

john22:06:12

Not sure if it works cross domain

john22:06:07

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

lread22:06:46

Interesting, thanks for sharing what you came up with!

john23:06:56

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

lread04:06:56

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

john05:06:54

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.

👍 2