From bdcfead62c927a8eaa57b09a7cfb4ae3f003104c Mon Sep 17 00:00:00 2001 From: Milo Turner Date: Sat, 11 Apr 2020 14:50:41 -0400 Subject: [PATCH] try to fix login by formatting the form correctly --- webcrawler | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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)