Compare commits
2 Commits
master
...
form-urlen
Author | SHA1 | Date |
---|---|---|
Milo Turner | bdcfead62c | |
Milo Turner | 8c4b525cbf |
|
@ -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?
|
||||
|
|
14
webcrawler
14
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)
|
||||
|
|
Loading…
Reference in New Issue