Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default Re: URL checking

    [email]mandy100@ihug.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::Parser is your friend.

    --
    A. Sinan Unur
    [email]asu1@c-o-r-n-e-l-l.edu[/email]
    Remove dashes for address
    Spam bait: mailto:uce@ftc.gov
    A. Sinan Unur Guest

  2. Similar Questions and Discussions

    1. checking for values
      hi. i'd like to perform a check on some values. these values are being populated into a structure that i'm then returning to flash. here's how it's...
    2. Checking inequality
      I have the following code in one of my trigger functions --------------------------------------------------------------- IF...
    3. checking duplicates
      Hi all, i'm trying to figure out how I can check for duplicates entries in an array and remove the duplicate. Example: 23,23,39,40,44,44 should...
    4. Just checking out the new look...
      ....it's definitely different! Will take some getting used to. :-) Barb
    5. Checking for process(es)
      Hello, Some of the programs i am currently writing (one depends on another) write their pids to file (create pid files). Now i want to check if...
  3. #2

    Default Re: URL checking

    Mandy <mandy100@ihug.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]tadmc@augustmail.com[/email] Perl programming
    Fort Worth, Texas
    Tad McClellan Guest

  4. #3

    Default Re: URL checking

    In article <6522b540.0306281641.4bbf5b23@posting.google.com >,
    Mandy <mandy100@ihug.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)
    ->parse($content);
    if ($found) {
    # found it
    } else {
    # didn't find it
    }
    }



    Good luck.

    Mark Jason Dominus Guest

Posting Permissions

  • You may not post new threads
  • You may 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