For example, I need to parse data from my imdb.com account. So, the task is get currently logged page. I taken the "id" cookie from browser. And make GET request, but it doesn't works.
(ns imdb.core
(:require [clj-http.client :as client])
(def ^:dynamic *base-url* "http://www.imdb.com/")
(def id {"id" {:value "my_value"
:domain "imdb.com"
:secure true
:max-age 3600}})
(defn get-my-page []
(client/get *base-url* {:cookies id}))
I think I need to set my id cookie to clj-http.cookies/cookie-store. But how?
clj-http
providesclj-http.cookies
namespace which you need to use.You can setup your cookie store, then call
clj-http.cookies/add-cookie
with your cookie extracted from browser and finallyclj-http.client/get
with setting:cookie-store
.On the other hand you might just maintain cookies across multiple HTTP calls as described in the documentation and just call the login page from
clj-http
directly. It will make your logic repeatable without manual steps like copying cookies from browser.