I have a tag containing a multi-line address that I would like to split into s...">

What is the best way to parse / split <div> based on tags <br/">

I have a tag containing a multi-line address that I would like to split into separate lines so that I can identify the city, zip code, etc.

for example

<div>Ministry of Magic
    <br />Whitehall
    <br />London
    <br />SW1A 2AA
</div>

I can do this without problems with the split function, for example (assuming the div address is in the $ text variable)

use feature 'say';
my @lines = split qr{<br\s?/>}, $text;
foreach my $line (@lines) {
    say $line;
}

displays

Ministry of Magic
Whitehall
London
SW1A 2AA

, HTML verboten, , HTML::TreeBuilder / HTML::Element, ' m , . look_down 'br', <br />. , <br> , , .

my $tree = HTML::TreeBuilder->new();
my @content = $tree->parse($text)->guts()->look_down(_tag => 'br');
foreach my $line (@content) {
    say $line->as_HTML;
}

<br />
<br />
<br />

, : 1) HTML:: TreeBuilder 2), HTML:: TreeBuilder, , ?

+4
1

( ) , , . , :

, , HTML. HTML . , HTML <div>, . , .

m!<\s*br\s*/?\s*>!, () HTML- , , , .

+2

Source: https://habr.com/ru/post/1608383/


All Articles