diff --git a/webcrawler b/webcrawler index db19728..f37009e 100755 --- a/webcrawler +++ b/webcrawler @@ -86,12 +86,16 @@ ;; Logs in with the given username and password (define (crawler-login username password) + (void (crawler-fetch 'POST LOGIN-PATH + (form-alist->http-body + `([username . ,username] + [password . ,password] + [csrfmiddlewaretoken . ,(crawler-get-csrf-token!)]))))) + +;; -> string? +(define (crawler-get-csrf-token!) (crawler-fetch 'GET LOGIN-PATH) - (define form-body - (format "username=~a&password=~a&csrfmiddlewaretoken=~a&next=" - username password (cookie-jar-ref (current-cookie-jar) "csrftoken"))) - (crawler-fetch 'POST LOGIN-PATH (string->bytes/utf-8 form-body)) - (void)) + (cookie-jar-ref (current-cookie-jar) "csrftoken")) ;; Checks if this is a URL we should crawl (define (crawler-valid-url? page-url)