Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Liek the title says. Uses LWP::Simple to fetch the ticker.
#!/usr/bin/perl -w =head1 parse the "Other Users XML Ticker" with C<index> and C<substr> For real. Probably won't work if the "DTD" changes (not bloody likely +). =cut use strict; use LWP::Simple; # other users xml ticker my $html = get('http://perlmonks.org/index.pl?node_id=15851'); die unless $html; warn $html; my $fh = [split "\n", $html]; while(@{$fh}) { parse_other_users(shift @{$fh}); } exit; sub parse_other_users { my $s = shift; #<user username="Corion" user_id="5348"></user> my $nX = index($s,'<user user_id='); # 14 my $iX = index($s,'" username="'); # 12 my $IX = index($s,'">', $iX + 11); my ($name, $id); if( $iX >=0 and $nX >=0 ) { printf '(%s)(%s)(%s)(%s)(%s)(%s)'."\n", $iX, $nX, $IX, $iX - $nX - 14, $name = substr($s, $nX + 14 + 1, $iX -$nX - 14 - 1), $id = substr($s, $iX + 12, $IX - $iX - 12),; } return; } __END__ <CHATTER><INFO site="http://perlmonks.org" sitename="Perl Monks">Rende +red by the Other Users XML Ticker</INFO><user user_id="22308" username="dws"></u +ser> <user user_id="83485" username="blakem"></user> <user user_id="65703" username="rob_au"></user> <user user_id="108447" username="demerphq"></user> <user user_id="61798" username="busunsl"></user> <user user_id="78196" username="lestrrat"></user> <user user_id="103344" username="Ryszard"></user> <user user_id="134513" username="metadoktor"></user> <user user_id="141348" username="Dog and Pony"></user> <user user_id="53018" username="juo"></user> <user user_id="12012" username="Malach"></user> <user user_id="107642" username="podmaster"></user> <user user_id="103824" username="perl::scribe"></user> <user user_id="143222" username="gdnew"></user> <user user_id="134230" username="tmiklas"></user> <user user_id="105312" username="thepen"></user> </CHATTER> (130)(110)(145)(6)(22308)(dws) (20)(0)(38)(6)(83485)(blakem) (20)(0)(38)(6)(65703)(rob_au) (21)(0)(41)(7)(108447)(demerphq) (20)(0)(39)(6)(61798)(busunsl) (20)(0)(40)(6)(78196)(lestrrat) (21)(0)(40)(7)(103344)(Ryszard) (21)(0)(43)(7)(134513)(metadoktor) (21)(0)(45)(7)(141348)(Dog and Pony) (20)(0)(35)(6)(53018)(juo) (20)(0)(38)(6)(12012)(Malach) (21)(0)(42)(7)(107642)(podmaster) (21)(0)(45)(7)(103824)(perl::scribe) (21)(0)(38)(7)(143222)(gdnew) (21)(0)(40)(7)(134230)(tmiklas) (21)(0)(39)(7)(105312)(thepen)

In reply to parse the "Other Users XML Ticker" with index and substr by PodMaster

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-28 15:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found