2013-11-28 39 views
1

我無法使css-selectors:query正常工作。 完全不明白什麼參數以什麼順序進入。 http://quickdocs.org/css-selectors/使用css-selectors查找節點:查詢

查看源代碼:

(defun query (inp &optional (trees buildnode:*document*)) 
    "Given a css selector, attempt to find the matching nodes in the passed in 
    dom-trees (defaults to the document)" 
    (%query inp trees)) 

我不知道inp代表什麼,但通過排除法假定它是指一個CSS選擇器字符串。

(defun get-page (url) 
    "Get STP(DOM alternative) representation of page" 
    (chtml:parse 
    (drakma:http-request url) 
    (cxml-stp:make-builder))) 

(css-selectors:query "a" (get-page "http://lisp.org/")) ; Doesn't work 
(css-selectors:query (get-page "http://lisp.org/") "a") ; Worth a try 

示例使用會大大有所幫助。

回答

1

編輯:Quickload css-selectors-stp讓它與STP一起工作。

我聯繫了作者,文檔已經變得更加清晰。對STP的支持應該已經合併並完成,但作者爲DOM編寫了此包,並且從未使用過STP。所以它應該爲STP工作,但不管因爲什麼原因。

以下工作:

(defun get-page (url) 
    "Get DOM representation of page" 
    (chtml:parse 
    (drakma:http-request url) 
    (cxml-dom:make-dom-builder))) 

(css-selectors:query "a" (get-page "http://lisp.org/")) ; Success!