Professional Web Applications Themes

Getting the href - PERL Beginners

Hi Everyone, What is good way to pull the href from a link in html? If I have links like: meow woof moo bark bahh <a href="here_kitty" class="domestic">meow</a> bahh moo bark How do I pull just the 'here_kitty' part? -- -- Jason Dusek ("`-''-/").___..--''"`-._ -- | `6_ 6 ) `-. ( ).`-.__.`) -- | (_Y_.)' ._ ) `._ `. ``-..-' -- | _..`--'_..-_/ /--'_.' ,' -- | (il),-'' (li),' ((!.-' --...

  1. #1

    Default Getting the href

    Hi Everyone,

    What is good way to pull the href from a link in html? If I have links like:

    meow woof moo bark bahh <a href="here_kitty" class="domestic">meow</a>
    bahh moo bark

    How do I pull just the 'here_kitty' part?
    --
    -- Jason Dusek ("`-''-/").___..--''"`-._
    -- | `6_ 6 ) `-. ( ).`-.__.`)
    -- | (_Y_.)' ._ ) `._ `. ``-..-'
    -- | _..`--'_..-_/ /--'_.' ,'
    -- | (il),-'' (li),' ((!.-'
    --
    Jason Guest

  2. #2

    Default Re: Getting the href

    > Hi Everyone, 
    like: 

    Use an HTML parsing module. HTML::TokePr::Simple has proven
    effective for me.

    There are regex possibilities, but mostly they create more headaches
    than they solve.

    http://danconia.org

    Wiggins Guest

  3. #3

    Default Re: Getting the href



    Jason Dusek wrote: 

    Hello,
     

    There's are modules that help you do it, but this may work for what you
    need:

    my href = $html =~ m/href\=\"((https?\:\/\/)?[\/\w\.\-]+)\"/ig;

    HTH

    Lee.M - JupiterHost.Net
     
    Jupiterhost.Net Guest

  4. #4

    Default Re: Getting the href


    >
    > Hello,

    >
    > There's are modules that help you do it, but this may work for what you
    > need:
    >
    > my href = $html =~ m/href\=\"((https?\:\/\/)?[\/\w\.\-]+)\"/ig;
    >[/ref]

    What if the link is ftp, mailto, etc. Contains username/password
    information? a Port? How about a query string? Javascript? White space
    around the "="..... To many questions unanswered, unanswered questions
    cause headaches, stick with the modules :-)...

    http://danconia.org

    Wiggins Guest

  5. #5

    Default Re: Getting the href



    Wiggins d Anconia wrote:
     
    >>
    >>Hello,
    >>
    >> 
    >>
    >>There's are modules that help you do it, but this may work for what you
    >>need:
    >>
    >>my href = $html =~ m/href\=\"((https?\:\/\/)?[\/\w\.\-]+)\"/ig;
    >>[/ref]
    >
    >
    > What if the link is ftp, mailto, etc. Contains username/password
    > information? a Port? How about a query string? Javascript? White space
    > around the "="..... To many questions unanswered, unanswered questions
    > cause headaches, stick with the modules :-)...
    >[/ref]

    I did say "may" :). For here_kitty it works but yes, modules are the way
    to go also because you may do this in lots of scripts and then if they
    add a new protocol, say , perl://, then all you have to do is update
    your module and all your scripts magically work with the new protocol
    without a thousand edits.
     
    Jupiterhost.Net Guest

  6. #6

    Default Re: Getting the href

    Jason Dusek wrote: 

    Hi Jason.

    For something simple like this HTML::SimpleLinkExtor is ideal.

    The program below should help.

    Rob


    use strict;
    use warnings;

    use HTML::SimpleLinkExtor;

    my $html = q{
    meow woof moo bark bahh <a href="here_kitty" class="domestic">meow</a>
    bahh moo bark
    };

    my $extor = HTML::SimpleLinkExtor->new;

    $extor->p($html);

    print "$_\n"foreach $extor->links;

    **OUTPUT

    here_kitty


    Rob Guest

  7. #7

    Default Regular Expresssion - Matching over multiple lines

    Hi All

    I have bunch of files that contain code like this:

    What I am trying to do is match <ps:img and this /> then check that this
    piece of code contains a alt= tag.


    <ps:img page="/images/portal/arrow_down.gif" border="0"
    width="9" height="6"
    alt="${string['lists.list.sort.ascending.alt']}"
    title="${string['lists.list.sort.ascending.alt']}" />


    And if it doen't print the lines where it's missing to screen or file.


    Cheers any help appreciated.









    Roman Guest

Similar Threads

  1. href help
    By prpldude in forum Macromedia ColdFusion
    Replies: 2
    Last Post: June 28th, 09:19 PM
  2. Get-Post in <A HREF>....
    By Bob Bedford in forum PHP Programming
    Replies: 3
    Last Post: December 16th, 10:40 AM
  3. href code
    By Konrad in forum ASP.NET General
    Replies: 5
    Last Post: July 28th, 01:56 PM

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