ciryon has asked for the wisdom of the Perl Monks concerning the following question:
Venerable Monks,
I'm trying to extract some info from a HTML-page. The information looks like <div>important_info_here</div> and there are many div-tags that I'm interested in. I want to store all info in an array. I have done something like:
... $content = get_content($url); @results = ($content =~ /<div>(.+)<\/div>/s); foreach(@results) { print; }
but I only get one match. What have I forgotten? I have searched through the monastery to no avail.
Update: Thanks for the replies! I followed tachyon's advice and did it this way:
I agree it would be better to use a real HTML parser, if I needed to extract more info.@divs = $content =~ m/<\s*div[^>]*>(.+?)<\s*\/div>/sig;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Many matches to an array
by tachyon (Chancellor) on Jul 15, 2004 at 11:07 UTC | |
|
Re: Many matches to an array
by Paulster2 (Priest) on Jul 15, 2004 at 11:09 UTC | |
by ciryon (Sexton) on Jul 15, 2004 at 11:38 UTC | |
by hsinclai (Deacon) on Jul 15, 2004 at 11:53 UTC | |
|
Re: Many matches to an array
by friedo (Prior) on Jul 15, 2004 at 11:14 UTC | |
|
Re: Many matches to an array
by wfsp (Abbot) on Jul 15, 2004 at 11:53 UTC | |
by tachyon (Chancellor) on Jul 15, 2004 at 11:59 UTC | |
by wfsp (Abbot) on Jul 15, 2004 at 12:28 UTC | |
by tachyon (Chancellor) on Jul 15, 2004 at 14:23 UTC | |
|
Re: Many matches to an array
by si_lence (Deacon) on Jul 15, 2004 at 11:16 UTC |