Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Parsing HTML

by ww (Archbishop)
on Jun 07, 2012 at 12:16 UTC ( #974927=note: print w/replies, xml ) Need Help??

in reply to Parsing HTML

This is just an "I wonder.... observation... about something that's very possibly not a factor, but the .html you show is peculiar to say the least... and if it isn't what Firebug is telling you, that might bear on your attempt to parse it.

<span>... </span> tags without attributes amount to no-ops.

I don't use Firebug so I have no solid reason to suspect that it's pruning tags for some reason... but, to me (YMMV), that makes at least as much sense as .html burdened with no-ops that have to ride the wire along with the substance of the page. It might be well to look at the source using view source and view generated source.

OTOH, maybe the code generating the page was written -- with very limited knowledge of .html -- by the DBA responsible for the data. That supposition arises from the use of &nbsp; in the date (six keystrokes where one would have been sufficient -- for no good reason I can discern).

PS: If you want each trip on its own, separate line, you need merely add a newline to the print $trip; at line 12 -- e.g.  print "$trip \n"; or print $trip . "\n";".

PPS: This puzzled me enough to make me actually look at the page in question... and it does, indeed, appear to have code very similar to what you've shown. There are a couple support files that were inaccessible, when I looked, but imputing any issue to them is merely speculative and probably a non-starter.

Replies are listed 'Best First'.
Re^2: Parsing HTML
by tobyink (Abbot) on Jun 07, 2012 at 20:43 UTC

    "<span>... </span> tags without attributes amount to no-ops."

    Not in this case - the page in question is using them to add line breaks within paragraphs. Something along the lines of:

    p.itinerari-info span { display: block }
    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re^2: Parsing HTML
by marcoss (Novice) on Jun 07, 2012 at 12:49 UTC

    Hi, the source code is exactly the same. I usually work with firebug and the source code simultaneosly, but firebug is cool. Putting newlines wouldn't be a solution, I think... because the output of the current script are cruise trip names with all the details, and what I need is an output that gets me the details separately (within the cruise trip).

      For a start, you might want to use split ( split ) to break up $trip into its elements. But your recent sample-output-desired post involves additional data (for example, "Trip Name"...) which I ignored in checking the original .html. Therefore (among other reasons), I'm not sure that
      is an appropriate pattern for split.

      Even if so, you'll still have to hard-code some punctuation (such as the colons in the subheads) and, perhaps, the newlines.

      The previous newline suggestion was based on the output you showed with multiple itineraries as a single line.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://974927]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2018-03-23 03:48 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (287 votes). Check out past polls.