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:

@divs = $content =~ m/<\s*div[^>]*>(.+?)<\s*\/div>/sig;
I agree it would be better to use a real HTML parser, if I needed to extract more info.

In reply to Many matches to an array by ciryon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.