Compare commits

...

2 Commits

Author SHA1 Message Date
Milo Turner bdcfead62c try to fix login by formatting the form correctly 2020-04-11 14:50:41 -04:00
Milo Turner 8c4b525cbf form-alist->http-body 2020-04-11 14:41:54 -04:00
2 changed files with 17 additions and 5 deletions

View File

@ -14,6 +14,7 @@
http-body?
empty-http-body
form-alist->http-body
write-http-body
force-http-body
in-http-body-chunks)
@ -21,6 +22,8 @@
(require racket/match
racket/port
racket/stream
net/uri-codec
"./util.rkt")
(module+ test
@ -154,6 +157,11 @@
(define empty-http-body #f)
;; (form-alist->http-body al) -> http-body?
;; al : (listof (cons/c symbol? string?))
(define (form-alist->http-body al)
(string->bytes/utf-8 (alist->form-urlencoded al)))
;; (write-http-body bdy [port]) -> void?
;; bdy : http-body?
;; port : output-port?

View File

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