Regular expressions, work with jsoup
-
Good night. Help me who knows how to spell it out, I can't figure it out at all.
I.
jsoup
through it receives the html code of one of the blocs:<!--Ad Injection:top--> <div style="margin-bottom:10px;"> <center> <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- MySite.ru Adaptive 1 --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-6747406633235216" data-ad-slot="7606784485" data-ad-format="auto"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </center> </div> <div> Моя подруга пообещала подарить своей дочке новый iPad за то, что она перейдет из шестого класса в седьмой. </div> <div> Мне в детстве родители обещали дать по шее, если не перейду! </div> <div class="addtoany_share_save_container addtoany_content_bottom"> <div class="a2a_kit a2a_kit_size_32 addtoany_list a2a_target" id="wpa2a_1"> <a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fwww.mysite.ru%2Farchives%2F45450&linkname=%D0%90%D0%BD%D0%B5%D0%BA%D0%B4%D0%BE%D1%82%20%D0%BE%D1%82" title="Facebook" rel="nofollow" target="_blank"></a> <a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fwww.mysite.ru%2Farchives%2F45450&linkname=%D0%90%D0%BD%D0%B5%D0%BA%D0%B4%D0%BE%D1%82%20%D0%BE%D1%82" title="Twitter" rel="nofollow" target="_blank"></a> <a class="a2a_button_vk" href="http://www.addtoany.com/add_to/vk?linkurl=http%3A%2F%2Fwww.mysite.ru%2Farchives%2F45450&linkname=%D0%90%D0%BD%D0%B5%D0%BA%D0%B4%D0%BE%D1%82%20%D0%BE%D1%82" title="VK" rel="nofollow" target="_blank"></a> <a class="a2a_button_odnoklassniki" href="http://www.addtoany.com/add_to/odnoklassniki?linkurl=http%3A%2F%2Fwww.mysite.ru%2Farchives%2F45450&linkname=%D0%90%D0%BD%D0%B5%D0%BA%D0%B4%D0%BE%D1%82%20%D0%BE%D1%82" title="Odnoklassniki" rel="nofollow" target="_blank"></a> <a class="a2a_button_google_plus" href="http://www.addtoany.com/add_to/google_plus?linkurl=http%3A%2F%2Fwww.mysite.ru%2Farchives%2F45450&linkname=%D0%90%D0%BD%D0%B5%D0%BA%D0%B4%D0%BE%D1%82%20%D0%BE%D1%82" title="Google+" rel="nofollow" target="_blank"></a> <a class="a2a_dd addtoany_share_save" href="https://www.addtoany.com/share"></a> <script type="text/javascript"><!-- if(wpa2a)wpa2a.script_load(); //--></script> </div> </div>
Apply method
replaceAll
for the transfer of lines and the regular method found on the Internet (in this example)<br>
No, but it's on the other pages of the steam site:.replaceAll("<br>", "\n").replaceAll("\\<[^>]*>", "")
I'm finally getting this:
// граница
(adsbygoogle = window.adsbygoogle || []).push({});
Моя подруга пообещала подарить своей дочке новый iPad за то, что она перейдет из шестого класса в седьмой.
Мне в детстве родители обещали дать по шее, если не перейду!
// граница
Please indicate how to adjust the text to read: remove the empty rows and gaps, but each empty row contains several gaps, apparently depending on how many tags were on it and to clean it up.
(adsbygoogle = window.adsbygoogle || []).push({});
The text needs to be extended:
Моя подруга пообещала подарить своей дочке новый iPad за то, что она перейдет из шестого класса в седьмой.
Мне в детстве родители обещали дать по шее, если не перейду!
-
Let
String page
- Your block. Then:Document doc = Jsoup.parse(page); Element firstTextElement = doc.select("div").get(1); Element secondTextElement = doc.select("div").get(2); String text = (firstTextElement.html() + "\n" + secondTextElement.html()).replace("<br>", "");
In the end,
text
text to be sought in which the<br>
will be replaced by lines."<br>"
Can be replaced by" <br>"
or"<br> "
, as the text contains this tag.