JSoup Tip How to get raw element text with newlines in Java - Parsing HTML and XML with JSoup

Опубликовано: 06 Октябрь 2024
на канале: EvilTester - Software Testing
3,702
19

A tip for using JSoup. If you want to get the raw text in an element e.g. newlines etc. (which JSoup normally parses out because HTML doesn't care about extra whitespace).

You can switch pretty printing off `doc.outputSettings().prettyPrint(false)` and access the `htm`

Or with the pretty printing on (which is the default) you can use the `text` in the `testNodes` to access the raw text.


*************

► Subscribe to My Channel For more videos like this http://www.youtube.com/subscription_c...

*************

►► Contact Details:

Read my writing and blogs at:

✓ http://www.eviltester.com
✓ http://www.seleniumsimplified.com
✓ http://www.javafortesters.com
✓ http://www.compendiumdev.co.uk

Follow me on social media:

★   / eviltester  
★   / eviltester   - @eviltester
★   / eviltester  
★   / eviltester  
★   / eviltester  

*************

►► Read my books

http://compendiumdev.co.uk/page/books

★ "Dear Evil Tester" - explore the tester's mind
★ "Java For Testers" - learn to code in Java
★ "Automating and Testing a REST API - a case study"

*************

►►Learn skills from my online training courses

http://www.compendiumdev.co.uk/page/o...

★ Selenium WebDriver With Java
★ Technical Web Testing 101
★ Evil Tester Talks Technical Testing
★ Case Study: Java Desktop Application Technical Training

*************