The parse
method is used to parse an HTML/XML content. This method is provided by the Mojo::DOM
module, which is an HTML/XML DOM parser with CSS selectors.
This is the first step we need to do to interact and perform operations on HTML/XML content.
$dom->parse('HTML/XML content')
The method accepts HTML/XML content
as a parameter.
This method returns the Mojo::DOM object for the given HTML/XML content
.
The given HTML is as follows:
<p>Inside paragraph</p>
The output is displayed as follows for the given HTML content:
<p>Inside paragraph</p>
It may look the same, but the parse
returned is a Mojo::DOM
object, on which we can perform operations.
use 5.010;use Mojo::DOM;# Parse the htmlmy $dom = Mojo::DOM->new->parse('<p>Inside paragraph</p>');# Display Mojo::DOM objectsay $dom;# Display text inside the Mojo::DOM objectsay $dom->all_text;
Mojo::DOM
module.parse
method to parse the HTML and store it in scalar $dom
.Mojo::DOM
object.all_text
method to perform an operation to get the content present inside the returned Mojo::DOM
object and print it.