Professional Web Applications Themes

URL checking - PERL Miscellaneous

[email]mandy100ihug.com.au[/email] (Mandy) wrote in news:6522b540.0306281641.4bbf5b23 posting.google.com: > Hi. > I can't seem to find any examples that will help me learn how to check > 2 things using a perl script. > > 1. Does a given page exist on a remote site > e.g. If i want to check that my homepage's pictures.html page exists. see [url]http://www.perldoc.com/perl5.8.0/lib/LWP.html#An-Example[/url] > 2. Does a page contain a url that I specify > e.g. does my pictures.html page contain a link to my diary.html page HTML::Pr is your friend. -- A. Sinan Unur [email]asu1c-o-r-n-e-l-l.edu[/email] Remove dashes for address Spam bait: mailto:uceftc.gov...

  1. #1

    Default Re: URL checking

    [email]mandy100ihug.com.au[/email] (Mandy) wrote in news:6522b540.0306281641.4bbf5b23
    posting.google.com:
    > Hi.
    > I can't seem to find any examples that will help me learn how to check
    > 2 things using a perl script.
    >
    > 1. Does a given page exist on a remote site
    > e.g. If i want to check that my homepage's pictures.html page exists.
    see [url]http://www.perldoc.com/perl5.8.0/lib/LWP.html#An-Example[/url]

    > 2. Does a page contain a url that I specify
    > e.g. does my pictures.html page contain a link to my diary.html page
    HTML::Pr is your friend.

    --
    A. Sinan Unur
    [email]asu1c-o-r-n-e-l-l.edu[/email]
    Remove dashes for address
    Spam bait: mailto:uceftc.gov
    A. Sinan Unur Guest

  2. #2

    Default Re: URL checking

    Mandy <mandy100ihug.com.au> wrote:
    > 1. Does a given page exist on a remote site

    Try and "fetch" it, if you get a good-looking response, then
    the resource exists.

    > 2. Does a page contain a url that I specify
    ^^^
    ^^^
    > I know there must be examples out there but my choice of keywords
    > hasn't been too productive yet.

    Errr, OK.


    perldoc -q fetch

    How do I fetch an HTML file?

    perldoc -q url

    How do I extract URLs?


    --
    Tad McClellan SGML consulting
    [email]tadmcaugustmail.com[/email] Perl programming
    Fort Worth, Texas
    Tad McClellan Guest

  3. #3

    Default Re: URL checking

    In article <6522b540.0306281641.4bbf5b23posting.google.com >,
    Mandy <mandy100ihug.com.au> wrote:
    >Hi.
    >I can't seem to find any examples that will help me learn how to check
    >2 things using a perl script.
    >
    >1. Does a given page exist on a remote site
    >e.g. If i want to check that my homepage's pictures.html page exists.
    I usually use the LWP::Simple module for that. First install the
    module by running the command:

    perl -MCPAN -e 'install LWP::Simple'


    Once you have LWP::Simple, you can use it to check for a page this
    way:

    use LWP::Simple;

    if (head($url)) {
    # it seems to exist
    } else {
    # not
    }
    >2. Does a page contain a url that I specify
    >e.g. does my pictures.html page contain a link to my diary.html page
    Similarly, you can use LWP::Simple to fetch the page's content, and
    then search through it looking for the link. Try

    use LWP::Simple;
    use HTML::LinkExtor; # "Link Extractor"

    my $content = get($url);
    if (defined $content) {
    my $found = 0;
    HTML::LinkExtor->new(sub { my $tag, %links = _;
    for (values %links) {
    $found = 1 if $_ eq "diary.html";
    }
    }, $url)
    ->p($content);
    if ($found) {
    # found it
    } else {
    # didn't find it
    }
    }



    Good luck.

    Mark Jason Dominus Guest

Similar Threads

  1. Checking for a numeric value
    By CF Nut in forum Macromedia ColdFusion
    Replies: 1
    Last Post: February 21st, 11:02 AM
  2. Checking state
    By HallyL in forum Macromedia Director 3D
    Replies: 1
    Last Post: November 2nd, 01:56 PM
  3. checking for no input
    By Kevin Pfeiffer in forum PERL Beginners
    Replies: 11
    Last Post: September 10th, 01:27 AM
  4. character checking
    By Paul Archer in forum PERL Beginners
    Replies: 0
    Last Post: August 31st, 01:53 AM
  5. Just checking out the new look...
    By imacgirl in forum Adobe Photoshop Elements
    Replies: 19
    Last Post: August 17th, 12:00 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139