Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: (crazyinsomniac) Re: Extract info from HTML

by George_Sherston (Vicar)
on Nov 12, 2001 at 13:51 UTC ( #124783=note: print w/replies, xml ) Need Help??

in reply to (crazyinsomniac) Re: Extract info from HTML
in thread Extract info from HTML

Huh, I always thought Tokeparser was something to do with getting stoned in an orderly recursive fashion. :) That was interesting. Q: can you make it kick out nodes below a depth of 1? - otherwise it's an index of all nodes, rather than an index of nodes where people give their etymology... Q2 - can it pick up the node_id of the named monk's node in this thread, rather than the named monk's home node?

George Sherston

Replies are listed 'Best First'.
Re: Re: (crazyinsomniac) Re: Extract info from HTML
by demerphq (Chancellor) on Nov 12, 2001 at 15:01 UTC
    Well, even though this wasnt addressed to me:

    Mine will extract all the above information just change the following lines

    print "($depth)$monkname posted '$monkname' on $date\n"; $hashref->{$monkname}->{$node_id}={ date=>$date, title=>$title, depth=>$depth };
    Then you can extract whatever you want.
    $VAR1 = { 'demerphq' => { '110238' => { 'depth' => '13', 'title' => 'Corions Name Space +', 'date' => 'Sep 05, 2001 at 01: +04' }, 'Home' => '108447', '110195' => { 'depth' => '12', 'title' => 'Re: Name Space', 'date' => 'Sep 04, 2001 at 15: +46' } }, 'George_Sherston' => { 'Home' => '103111', '124767' => { 'depth' => '13', 'title' => 'Re: Re: Nam +e Space', 'date' => 'Nov 11, 2001 + at 22:33' }, 'Name Space' => { 'depth' => '9', 'title' => 'Name Sp +ace', 'date' => 'Sep 04, +2001 at 13:33' }, '121046' => { 'depth' => '14', 'title' => 'Re: Re: Re: + Name Space', 'date' => 'Oct 24, 2001 + at 01:21' }, '117665' => { 'depth' => '13', 'title' => 'Re: TheOrbT +wo\'s Name Space', 'date' => 'Oct 09, 2001 + at 00:05' }, '117303' => { 'depth' => '13', 'title' => 'Re: Re: Nam +e Space', 'date' => 'Oct 07, 2001 + at 03:57' }, '110244' => { 'depth' => '13', 'title' => 'Re: Re: Nam +e Space', 'date' => 'Sep 05, 2001 + at 01:58' }, '122854' => { 'depth' => '13', 'title' => 'Re: Re: Nam +e Space', 'date' => 'Nov 02, 2001 + at 08:07' } }, };
    Note that the depths are as follows:9 root node, 12 reply, 13, reply to a reply...
    But a thought: You dont want the posts from just a fixed depth in the parse tree. That would for instance eliminate you from the list (you dont have a reply to yourself) as well as anyone who explained their name in a reply to another persons explaination, merphq would be an example, however I believe there are more as well.

    Actually, one of the more interesting issues with this thread was acurately picking up all names from all levels, there is an annoying habit of <UL> tags messing up the pattern, also of the main post being marked up differently.

    Anyway, Ill revisit this a bit later, :-)

    Yves / DeMerphq
    Have you registered your Name Space?

      Those whom the gods would destroy they first interest them in parsing natural language... really, in order to come up with a satisfactory solution to this, we're going to have to find a way to distinguish between the content of nodes... we need a script that can make an intelligent guess whether the node is a response or an etymology. This is a bit too rich for my blood, but I look forward to seeing it done :)

      George Sherston
Re: Re: (crazyinsomniac) Re: Extract info from HTML
by crazyinsomniac (Prior) on Nov 12, 2001 at 15:27 UTC
      Well, to be mildly critical there are two (or more depending on how you look at it) scenarios where we can/need to extract information from. Yours only matches one fixed version (yes i know it was deliberate decision :-) now for the record (and in rehersal for that tutorial you suggested :-) Ill list the others:
      # Main node on page (Top most) <TD valign=middle> <H3>Name Space</H3> <FONT size=2> ' by ' <A HREF="/">George_S +herston</A> ' on Sep 04, 2001 at 13:33' </FONT> </TD> # Primary Reply (crazyinsomniacs pattern) <TD colspan=2> <font size=2> <A HREF="/">Re: Name + Space</A> <BR> ' by ' <A HREF="/">demerphq +</A> ' on Sep 04, 2001 at 15:46' </font> </TD> # Note that the <UL> tag is incorrectly nested with regards to the <FO +NT> tag # Reply to a reply <TD colspan=2> <UL> <font size=2> <A HREF="/">Re: +Re: Name Space</A> <BR> ' by ' <A HREF="/">Geor +ge_Sherston</A> ' on Sep 05, 2001 at 01:58' </UL> </font> # Reply to a reply of a reply # each extra layer of depth has an extra <UL> tag inserted <TD colspan=2> <UL> <UL> <font size=2> <A HREF="/"> +Re: Re: Re: Name Space</A> <BR> ' by ' <A HREF="/"> +George_Sherston</A> ' on Oct 24, 2001 at 01:21' </UL> </UL> </font> </TD>
      Note the buggy HTML? :-)

      So what I did was look for the content of the FONT tag. If it matches a 'finger print' for one of the following two

      <font size=2> # Optional part begins <A HREF="/">Re: Re: Re +: Name Space</A> <BR> # Optional part ends ' by ' <A HREF="/">George_She +rston</A> ' on Oct 24, 2001 at 01:21' </font>
      Then I do a few more checks to make sure it isnt a spurious match, if they pass then I consider it the title/author/date of the node. A bit of extraction of the tags attributes and presto, we have the home node and post node ids. (With the exception of the main post, where we can only extract the title, not the ID)

      This would be sooooo much easier if there were class attributes in the tags, such as <TD class="post">, but considering the buggy HTML, I suppose class attributes are low on the priority list. (BTW, cant wait to join the PM dev team, id like to have a crack at cleaning up some of the HTML, now that im getting into parsing it :-)

      Yves / DeMerphq
      Have you registered your Name Space?

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://124783]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2021-10-16 21:51 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (70 votes). Check out past polls.