     
 
     (if (not (empty? class-list)) 
-      (map #(format "%s[%s]" tag %) formatted-classes)
-      (list tag))))
+      (map #(cond (and (not is-first?)
+                       (not is-last?))             
+                  (format "%s[%s]" tag %)
+
+                  is-first?
+                  (format "%s[%s][1]" tag %)
+
+                  is-last?
+                  (format "%s[%s][last()]" tag %)) formatted-classes)
+      (cond (and (not is-first?)
+                 (not is-last?))
+            (list tag)
+
+            is-first?
+            (list (format "%s[1]" tag))
+
+            is-last?
+            (list (format "%s[last()]" tag))))))
 
 (defn tag-node->xpath
   [a-tagnode]

                                      (.getAttributes)
                                      (.getNamedItem "href"))
                                  (try
                                    (not= (-> a-tag
                                              (.getAttributes)
                                              (.getNamedItem "rel")
                                              (.getValue))
                                          "nofollow")
                                    (catch NullPointerException e true))
                                  
                                  (not= (uri/scheme (-> a-tag
                                                        (.getAttributes)
                                                        (.getNamedItem "href")
                                                        (.getValue)))
                                        "javascript")
                                  (not (some #{(uri/resolve-uri
                                                url
                                                (-> a-tag
                                                    (.getAttributes)
                                                    (.getNamedItem "href")
                                                    (.getValue)))}
                                             (set blacklist)))))
                           a-tags)
           
           nodes-xpaths   (map

                                              (.getNamedItem "href")
                                              (.getValue))]
                                 {:node x
                                  :href (try
                                          (uri/fragment
                                           (uri/resolve-uri url link)
                                           nil)
                                          (catch Exception e nil))
                                  :text (.getTextContent x)}))
                             a-tags-w-hrefs)))]
       
       (reduce
        (fn [acc [an-xpath node]]
          (merge-with
           concat acc {an-xpath [node]})) {} nodes-xpaths))))
