; Return a list of URLS as located in the a elements of ast. (define (extract-links ast) (if (ast? ast) (let ((name (ast-element-name ast)) (subtrees (ast-subtrees ast)) ) (if (equal? name "a") (let ((href-attr-value (find-href-attribute (ast-attributes ast)))) (if href-attr-value (list href-attr-value) '())) (extract-links-ast-list subtrees))) '())) ; Return a list of URLS as located in the a elements of ; the list of ast's as passed in ast-list. (define (extract-links-ast-list ast-list) (if (null? ast-list) '() (append (extract-links (car ast-list)) (extract-links-ast-list (cdr ast-list))))) ; Return the href attribute value from a property list ; Return #f if no href attribute is found. ; Pre-condition: attr-p-list is a property list - ; of even length. (define (find-href-attribute attr-p-list) (if (null? attr-p-list) #f (let ((attr-name (car attr-p-list)) (attr-value (cadr attr-p-list)) (attr-rest (cddr attr-p-list))) (if (eq? attr-name 'href) attr-value (find-href-attribute attr-rest)))))