A quick and dirty script that will suck down the Top Stories from Yahoo's page and spit them into an
  • field. That's about it. Useful for cron or sucking in via SSI pages. (Do they have an RDF/RSS anywhere?)
  • #!/usr/bin/perl use strict; use LWP::Simple; # declare our variables for safety my ($sawFCEnd, $sawBR, $link, $title); # suck down the webpage my $content = get("http://dailynews.yahoo.com/htx/ts/"); # split the content on each new line, and loop through the lines foreach(split(/\n/, $content)) { # if we see FCEnd, we're getting close if (/<!-- FCEnd -->/) { $sawFCEnd=1; next; }; # if we see two <br>'s on a line, we're even closer if ($sawFCEnd && /<br><br>/) { $sawBR=1; next; }; # if we saw the two <br>'s, this must me our news # link, OR if the line starts with <a href=... we # must have a news link too... if ($sawBR or /^<a href=/) { # clear the variables for the next loop $sawFCEnd=0; $sawBR=0; # grep the link and title into variables ($link, $title) = (/<a href="(.*)"><b>(.*)<\/b><\/a>/); # print a line only there's a $link print "<LI><A HREF=\"$link\">$title</A>\n" if defined($link); } # start over again next; }

    In reply to Quick Yahoo Top Stories Parser by Anonymous Monk

    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.