Используя структуру JSoup, я пытаюсь выполнить итерацию по нижнему div и извлечь текст в каждом из тегов <p>
в массив. Поскольку список <div>
и <p>
равен бесконечно длинному, цикл do/while или цикл for будет предпочтительным методом получения информации в <p>
.JSoup - Приращение с помощью тегов/массивов
Я не знаю, как перебирать <div>
тегов ниже, потому что я не знаю, как следить за то, что <p>
тегов из которых <div>
«ы Я хранение в массив. Извинения, если ответ очевиден, поскольку я несколько новичок в Java и программировании в целом.
Большое вам спасибо за помощь. Дайте мне знать, если я могу добавить, что это поможет.
Пример HTML (предположит, что повторяет сотни раз):
<div class="happy-div"> // want everything within this div to be in one array element
<p>good text here.</p>
<p>More good Text here.</p>
<p>Some good stuff here.</p>
</div>
<div class="sad-div"> // want everything within this div to be in a separate array element
<p>Some unhappy text here.</p>
<p>More unhappy Text here.</p>
<p>Some unhappy stuff here.</p>
</div>
<div class="depressed-div"> // everything within this div to be in a separate array element
<p>Some melancholy text here.</p>
<p>More melancholy Text here.</p>
<p>Some melancholy stuff here.</p>
</div>
.... repeats hundreds of times
псевдокод:
String[] arrayOfP;
for (int i = 0; i < numberOfDivs; i++)
{
arrayOfP[i] = doc.select("All of the text in the <p> tags within the div we've incremented to")
System.out.println(arrayOfP[i])
}
Ожидаемого результат:
При печати содержимого строки значения элемента массива, I w ульд ожидать, чтобы увидеть это:
arrayofP[1] Some good text here. More good Text Here. Some good stuff here.
arrayofP[2] Some unhappy text here. More unhappy Text Here. Some unhappy stuff here.
arrayofP[3] Some melancholy text here. More melancholy Text Here. Some melancholy stuff here.
....
Post значения массива образцов. – newuser
Я уточнил область ожидаемых результатов. Это помогает? –