Note that there are some explanatory texts on larger screens.

plurals
  1. POScraping Table with Nokogiri and need JSON output
    primarykey
    data
    text
    <p>So, I have a table with multiple rows and columns.</p> <pre><code>&lt;table&gt; &lt;tr&gt; &lt;th&gt;Employee Name&lt;/th&gt; &lt;th&gt;Reg Hours&lt;/th&gt; &lt;th&gt;OT Hours&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Employee 1&lt;/td&gt; &lt;td&gt;10&lt;/td&gt; &lt;td&gt;20&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Employee 2&lt;/td&gt; &lt;td&gt;5&lt;/td&gt; &lt;td&gt;10&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>There is also another table:</p> <pre><code>&lt;table&gt; &lt;tr&gt; &lt;th&gt;Employee Name&lt;/th&gt; &lt;th&gt;Revenue&lt;/th&gt; &lt;/tr&gt; &lt;td&gt;Employee 2&lt;/td&gt; &lt;td&gt;$10&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Employee 1&lt;/td&gt; &lt;td&gt;$50&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>Notice that the employee order may be random between the tables.</p> <p>How can I use nokogiri to create a json file that has each employee as an object, with their total hours and revenue?</p> <p>Currently, I'm able to just get the individual table cells with some xpath. For example:</p> <pre><code>puts page.xpath(".//*[@id='UC255_tblSummary']/tbody/tr[2]/td[1]/text()").inner_text </code></pre> <p><strong>Edit:</strong></p> <p>Using the page-object gem and the link from @Dave_McNulla, I tried this piece of code just to see what I get:</p> <pre><code>class MyPage include PageObject table(:report, :id =&gt; 'UC255_tblSummary') def get_some_information report_element[1][2].text end end puts get_some_information </code></pre> <p>Nothing's being returned, however.</p> <p>Data: <a href="https://gist.github.com/anonymous/d8cc0524160d7d03d37b" rel="nofollow">https://gist.github.com/anonymous/d8cc0524160d7d03d37b</a></p> <p>There's a duplicate of the hours table. The first one is fine. The other table needed is the accessory revenue table. (I'll also need the activations table, but I'll try to merge that from the code that merges the hours and accessory revenue tables.</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.
 

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