Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For <code>nth-of-type</code>, does the following example help?</p> <pre><code>user&gt; (require '[net.cgrand.enlive-html :as html]) user&gt; (def test-html "&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;first&lt;/p&gt;&lt;p&gt;second&lt;/p&gt;&lt;p&gt;third&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;") #'user/test-html user&gt; (html/select (html/html-resource (java.io.StringReader. test-html)) [[:p (html/nth-of-type 2)]]) ({:tag :p, :attrs nil, :content ["second"]}) </code></pre> <p>No idea about the second issue. Your approach seems to work with a naive test:</p> <pre><code>user&gt; (def test-html "&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;div&gt;&lt;p&gt;in div&lt;/p&gt;&lt;/div&gt;&lt;p&gt;not in div&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;") #'user/test-html user&gt; (html/select (html/html-resource (java.io.StringReader. test-html)) [:body :&gt; :p]) ({:tag :p, :attrs nil, :content ["not in div"]}) </code></pre> <p>Any chance of looking at your actual HTML?</p> <p><strong>Update:</strong> <em>(in response to the comment)</em></p> <p>Here's another example where "the second <code>&lt;p&gt;</code> inside the <code>&lt;div&gt;</code> inside the second <code>&lt;div&gt;</code> inside whatever" is returned:</p> <pre><code>user&gt; (def test-html "&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;div&gt;&lt;p&gt;this is not the one&lt;/p&gt;&lt;p&gt;nor this&lt;/p&gt;&lt;div&gt;&lt;p&gt;or for that matter this&lt;/p&gt;&lt;p&gt;skip this one too&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;span&gt;&lt;p&gt;definitely not this one&lt;/p&gt;&lt;/span&gt;&lt;div&gt;&lt;p&gt;not this one&lt;/p&gt;&lt;p&gt;not this one either&lt;/p&gt;&lt;div&gt;&lt;p&gt;not this one, but almost&lt;/p&gt;&lt;p&gt;this one&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;certainly not this one&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;") #'user/test-html user&gt; (html/select (html/html-resource (java.io.StringReader. test-html)) [[:div (html/nth-of-type 2)] :&gt; :div :&gt; [:p (html/nth-of-type 2)]]) ({:tag :p, :attrs nil, :content ["this one"]}) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload