Fork me on GitHub
#etaoin
<
2022-09-02
>
jjttjj18:09:48

How could I get the src attribute for all images on a page? query-all seems to return a sequence of "identifier strings". How can I go from an identifier string to an element attribute?

lread19:09:48

Hi @jjttjj! When working with elements returned by queries use get-element-attr-el instead of get-element-attr :

(require '[etaoin.api :as e])

(def driver (e/chrome))
(e/go driver "")
(->> (e/query-all driver {:tag :img})
     (map (fn [x] (e/get-element-attr-el driver x "src"))))
;; => ("")

jjttjj19:09:27

Aha, thanks!

lread19:09:14

You are most welcome, happy to help!

👍 1
lread19:09:38

(don’t know why I threaded my reply 🤷, added my reply to channel)

jjttjj18:09:41

I would expect something like

(e/go driver "")
  (->> (e/query-all driver {:tag :img})
       (map (fn [x] (e/get-element-attr driver x "src")))) 
to work, but the values returned by query-all are interpreted as xpaths

lread19:09:48

Hi @jjttjj! When working with elements returned by queries use get-element-attr-el instead of get-element-attr :

(require '[etaoin.api :as e])

(def driver (e/chrome))
(e/go driver "")
(->> (e/query-all driver {:tag :img})
     (map (fn [x] (e/get-element-attr-el driver x "src"))))
;; => ("")