Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Consider</p> <ul> <li>Creating a class that holds the td1 String and the td2 or price String, say let's call it DiabloGoldRow or some-such.</li> <li>creating an Collection of this class, say, <code>ArrayList&lt;DiabloGoldRow&gt;</code>, or if you want to be able quickly get information based on the td1 String, a <code>HashMap&lt;String, DiabloGoldRow&gt;</code>.</li> <li>Then using JSoup to isolate the information in the table, and then iterate through it in a for loop, creating instances of DiabloGoldRow objects and putting them into the ArrayList or other collection (i.e., HashMap).</li> </ul> <p>I'll leave the details of the code as an exercise for the student.</p> <p><strong>Edit</strong><br> You ask, </p> <blockquote> <p>Why do I need to create a separate class to hold the variables?</p> </blockquote> <p>Because you need to hold the two pieces of information held on each row close together and may need to search on one to obtain the other. It's a lot cleaner to do it this way than to use 2D arrays or parallel arrays. What is your objection towards doing this? </p> <p><strong>Edit 2</strong><br> You state, </p> <blockquote> <p>I am not opposed to anything. I'm simply wondering how that will help me grab the values I need. My question was using the methods I normally do, I cannot grab the data I want to. I was simply looking for a different syntax to grab the specified data.</p> </blockquote> <p>Again, one way you can do this with a for loop. Simply loop through the rows of the table:</p> <pre><code> Elements eles = doc.select("table tr"); for (int i = 0; i &lt; eles.size(); i++) { Elements rowEles = eles.get(i).select("form"); Elements goldEles = rowEles.select("[name=gold]"); String goldValue = goldEles.attr("value"); Elements priceEles = rowEles.select("[name=price]"); String priceValue = priceEles.attr("value"); System.out.printf("%-7s: %-5s%n", goldValue, priceValue); } </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.
 

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