Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

roboticus has shown how to deal with the multi-line para problem, so I'm omitting that. But as the AM above suggests, using an appropriate module or modules can save you much grief.

What follows is NOT code to adopt or emulate; rather it is intended to suggest the pitfalls you may encounter in dealing the html. Web pages may be fully compliant, well-structured (for readability and maintenance); and reasonably consistent within a <ol>, <ul>, or <table> (and those are just "fer'instances") but don't bet the farm on that!

That which you're scraping may well be less than well-formed, compliant or consistent. And that makes parsing difficult. This bad example confines itself to some minor variance and only in the rendered portion of a link:

#!/usr/bin/perl use Modern::Perl; # 934485 my ($name, @names, @scrapings, $scraping); while ( <DATA> ) { $scraping = $_; push @scrapings, $scraping; } for $scraping(@scrapings) { $scraping =~ /(\d\w+ # begin capture, num followed by 1 or more +wordchars [. ]* # charclass of dot or space (?: # non-capture grouping \w+ # wordchars [. ]+ # one or more of a literal dot or + space )* # group is OPTIONAL by quantifyin +g it as "0 or more" [\w-]+ # wordchars or hyphens \s* # zero or more spaces ) # end capture before <\/a> # close link_renderable and href /x; # extended format if ($1) { $name = $1; push @names, $name; } } for $name (@names) { say $name; } say "\n\t Done"; __DATA__ <li><a href="page.aspx?1ar3xlr29">1Mary Mary QuiteContrary </a></li> <li><a href="page.aspx?43xlr17">2Sam Samuels</a></li> <li><a href="page.aspx?3719rlr17qt">3Joe.Bones</a></li> <li><a href="page.aspx?a=c4bc46eswsdw32fcc">4John.Martines </a></li> <li><a href="page.aspx?a=0a2b-a99d-3754eb2f5e35">5Mary Jones</a></li> <li><a href="page.aspx?a=1ef7b100-8dc4-4b40-871c-68b1d0">6Fernando Pra +deras</a></li> <li><a href="page.aspx?a=e8ec1d77-ee83-4797-b9c4-7676053a4926"> 7blifs +tik</a></li> <li>foobar baz blivitz <a href="page.aspx?a=e8ec1d77" class="b">8Frede +rick B. Ohlmsted</a> more blah blah blah and so on ad nauseum....</l +i> <li><a href="page.aspx?a=c4bc46eswsdw32fcc">9Ernesto Maria Santiago-Co +rtez</a></li>

Executing that script produces what I believe to be data consistent with your spec:

1Mary Mary QuiteContrary 2Sam Samuels 3Joe.Bones 4John.Martines 5Mary Jones 6Fernando Praderas 7blifstik 8Frederick B. Ohlmsted 9Ernesto Maria Santiago-Cortez Done

But look at the hoops we jumped thru to get here -- for what are fundamentally small-potatoes differences in the style of the names. Strong Suggestion: Don't do it this way.


In reply to Re: A regex question by ww
in thread A regex question by emelianenko

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (2)
    As of 2014-09-20 15:22 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (160 votes), past polls