Loading ...
Sorry, an error occurred while loading the content.

can someone please help with the LWP module

Expand Messages
  • bbrown1116
    I m trying to link to Central Commands website to dynamically generate links for each daily briefing whether the briefing is held by CENTCOM or the DoD. They
    Message 1 of 1 , Apr 1, 2003
    • 0 Attachment
      I'm trying to link to Central Commands website to dynamically
      generate links for each daily briefing whether the briefing is held
      by CENTCOM or the DoD. They publish their briefings in year month
      day format as 20030327.htm, but that doesn't necessairly mean that
      URL is the CENTCOM Briefing for 03/27/2003, because if the DoD also
      has that gets one number for 20030328.htm. And since I can't
      differentiate between the two, what I'm wanting to do is have my
      program determine what the pages <title>Title</title> is, and have
      that displayed as the link to the page. And while my program will
      determine if the page exists and display a link to the page, I can't
      seem to get it to display the pages title as the link to
      corresponding page. I've read the documentation, and just can't seem
      to figure out how to properly write the code, to what it is I want.
      I would sure appreciate any help anyone can give me, thank you! The
      code I'm using is listed below:

      #!C:/Perl/bin/perl -w

      use CGI::Carp qw(fatalsToBrowser);
      use LWP::Simple;
      use LWP::UserAgent;
      require HTTP::Response;
      require HTTP::Message;
      require HTTP::Headers;
      print "Content-type:text/html\n\n";
      my (@url);
      $url[0]
      = "http://www.centcom.mil/CENTCOMNews/Transcripts/20030329.htm";
      $url[1]
      = "http://www.centcom.mil/CENTCOMNews/Transcripts/20030330.htm";
      $url[2]
      = "http://www.centcom.mil/CENTCOMNews/Transcripts/20030331.htm";

      my $ua = LWP::UserAgent->new;
      $mess = HTTP::Message->new;
      foreach my $url (@url) {
      $count += 1;
      my $request = HTTP::Request->new(GET => $url);
      my $h = HTTP::Headers->new(Content_Base => $url);
      my $response = $ua->request($request);
      my $title = $mess->title;
      print $title, "<br>";
      my $title1 = $ua->get($h->header);
      if ($response->is_success) {
      #print $response->content;
      print "<a href=$url
      target=new_window>$title1</A><br>";
      } else {
      print $response->error_as_HTML;
      }
      }

      I have an example to get the title using using both the
      HTTP::Headers module, and the HTTP::Message module. For the
      HTTP::Message example the return value is undef, and for the
      HTTP::Headers the output looks like this:

      HTTP::Response=HASH(0x1743fcc)

      HTTP::Response=HASH(0x1910d14)

      HTTP::Response=HASH(0x174432c)

      Can someone please tell me what it is I'm doing wrong, and how to
      fix my code so it will properly get the titles. Thank you so much
      for your help!
      BTW - The URL's in $url[$_] are only meant to test the code right
      now. I have the code to dynamically create the $_.htm files using
      the Time::Piece module like so:

      my $t = localtime;
      my $date = $t->ymd("");

      and then running it through a foreach loop copy the $date and
      increment or decrement as neccessary to get the current pages.
      Anyway, if anyone can help me, I would sure appreciate it.
      Thank you!
    Your message has been successfully submitted and would be delivered to recipients shortly.