Note that there are some explanatory texts on larger screens.

plurals
  1. POJSoup: extracting text and store it in multiple variables
    text
    copied!<p>i have the following situation:</p> <p>I want to extract all text between the "span" tags</p> <pre><code>&lt;div class="examplediv"&gt; &lt;ul&gt; &lt;li&gt;&lt;span&gt;1&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span&gt;2&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span&gt;3&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span&gt;4&lt;/span&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div class="examplediv"&gt; &lt;ul&gt; &lt;li&gt;&lt;span&gt;5&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span&gt;6&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span&gt;7&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span&gt;8&lt;/span&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div class="examplediv"&gt; &lt;ul&gt; &lt;li&gt;&lt;span&gt;9&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span&gt;10&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span&gt;11&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span&gt;12&lt;/span&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div class="examplediv"&gt; &lt;ul&gt; &lt;li&gt;&lt;span&gt;13&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span&gt;14&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span&gt;15&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span&gt;16&lt;/span&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>Where all the first lines are going to be stored in variable "A", all the second lines in "B", all the third lines in "C" and so on.</p> <p>My Java code is as follows:</p> <pre><code>File input = new File("/tmp/input.html"); Document doc = Jsoup.parse(input, "UTF-8", "http://example.com/"); Elements exa = doc.select(".examplediv span"); if (exa != null) { for (int i = 0; i &lt; exa.size(); i++) { A[i] = exa.get(i).text(); } } </code></pre> <p>This code puts all lines in variable "A".</p> <pre><code>A = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 </code></pre> <p>And i want it to be stored like this:</p> <pre><code>A = 1,5,9,13 B = 2,6,10,14 C = 3,7,11,15 D = 4,8,12,16 </code></pre> <p>Please give me some advice on how to do this. Thanks and Happy Holidays.</p> <p>EDIT ---------------------------------</p> <p>I had this idea:</p> <pre><code>if (exa != null) { for (int i = 0; i &lt; exa.size(); i++) { A[i] = exa.get(0).text(); B[i] = exa.get(1).text(); C[i] = exa.get(2).text(); D[i] = exa.get(3).text(); } } </code></pre> <p>It gives me</p> <pre><code>A = 1,2,3,4 B = 1,2,3,4 C = 1,2,3,4 D = 1,2,3,4 </code></pre> <p>It repeats the first 4 spans.</p> <p>How can i at least get:</p> <pre><code>A = 1,2,3,4 B = 5,6,7,8 C = 9,10,11,12 D = 13,14,15,16 </code></pre>
 

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