A
A
artshelom2018-05-10 18:44:30
Java
artshelom, 2018-05-10 18:44:30

How to get the text which is after the br tags?

How can I take the text of which is between the tags (I can use any library, but JSOUP is better) for example:

<div class="123">
    <div class="spoiler-title "><b>....</b></div>
    <br>Текст который нужно взять`введите сюда код`
    <div class="spoiler-body">....</div>
</div>
<br>Текст который нужно взять`введите сюда код
<hr>
<div class="spoiler-title "><b>....</b></div>

Here's how to take the text between the divs, I tried to take the brothers, but the text was not there ( How can it be otherwise

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alexalexes, 2018-05-10
@artshelom

Not familiar with JSOUP, however, project my solution to Java, the idea is the same:

<div class="123">
      <div class="spoiler-title"><b>....</b></div>
      <br>Текст который нужно взять`введите сюда код`
      <div class="spoiler-body">....</div>
    </div>
    <script>
    (function()
    {
      var div_elems = document.getElementsByClassName('123');
      var div123 = div_elems[0];
      // Следующим шагом вместо того, чтобы получать содержимое тега ( = div123.innerHTML) пройдемся по его потомкам
      var childs = div123.childNodes; 
      var div_spoiler_title = childs[0];
      var br_elem = childs[1];
      var text_elem = childs[2]; // в этом узле ваш текст
      var div_spoiler_body = childs[3];
    })();
    </script>

PS: If the library is not able to select a textNode type node inside the container, then this is a question for the library.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question