Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>...I've noticed that Firebug produces some xpath expressions that don't work well with Nokogiri (or its dependency). I'm having better luck with Chrome's Debug XPath output.</p> </blockquote> <p>The problem with Firebug, or many other XPath outputs from a browser, is they follow the HTML spec when generating the XPath and synthesize a <code>&lt;tbody&gt;</code> tag, even if the original source doesn't have one. The XPath reflects that. </p> <p>We pass the raw HTML to Nokogiri for parsing, along with the erroneous XPath, and Nokogiri can't find the <code>&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;</code> chain. </p> <p>Here's a for instance. Starting with this HTML:</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; foo &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Save it to a file and open it in Firefox, Chrome or Safari, then view the source, and look at it in Firebug or its equivalent.</p> <p>You'll see something like this, which came from Firefox:</p> <pre><code>&lt;table&gt; &lt;tbody&gt;&lt;tr&gt; &lt;td&gt; foo &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; </code></pre> <p>To fix this, don't rely on the XPath generated by the browser, and confirm the table's structure by looking at only the <em>RAW</em> HTML in a text editor. The "view source" option is useful for some things, but if you see any <code>&lt;tbody&gt;</code> tags be suspicious and revert to checking with the editor.</p> <p>Also, you don't need the entire chain of tags to reach an inner tag. Instead, look for some landmarks along the way that will help you find your target node(s). Most HTML pages these days have <code>class</code> and <code>id</code> parameters in important tags. ID parameters in particular are great because they have to be unique. If other parameters exist that are unique, those can work too. </p> <p>Sometimes you won't find an identifying tag immediately prior to the one you want, but there is something embedded in it. Then, locate that embedded tag and step up the chain until you find what you want. Using XPath you can use the <code>..</code> (parent), but with CSS you have to rely on Nokogiri::XML::Node's <code>parent</code> method because Nokogiri and CSS don't support a selector for the parent (yet).</p>
    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. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    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