clojure の enlive ライブラリを使用して Web サイトをスクレイピングしようとしています。対応する CSS セレクターは次のとおりです。
body > table:nth-child(2) > tbody > tr > td:nth-child(3) > table > tbody > tr > td > table > tbody > tr:nth-child(n+3)
jqueryを使用して上記のセレクターをテストしましたが、動作します。しかし、上記を enlive のセレクター構文に変換する方法がわかりません。私は次の行に沿って何かを書き込もうとしました:
(ns vimindex.core
(:gen-class)
(:require [net.cgrand.enlive-html :as html]))
(def ^:dynamic *vim-org-url* "http://www.vim.org/scripts/script_search_results.php?order_by=creation_date&direction=descending")
(defn fetch-url [url]
(html/html-resource (java.net.URL. url)))
(defn scrape-vimorg []
(println "Scraping vimorg")
(println
(html/select (fetch-url *vim-org-url*)
[:body :> [:table (html/nth-child 2)] :> :tbody :> :tr :> [:td (html/nth-child 3)] :> :table :> :tbody :> :tr :> :td :> :table :> :tbody :> [:tr (html/nth-child 1 3)]])))
; body > table:nth-child(2) > tbody > tr > td:nth-child(3) > table > tbody > tr > td > table > tbody > tr:nth-child(n + 3)
; Above selector works with jquery
(defn -main
[& args]
(scrape-vimorg))
しかし、空の応答が返されます。上記の CSS セレクターを enlive の構文で翻訳する方法を教えてください。
どうもありがとう。
編集済み:完全なコードを含める。