www.webdeveloper.com
Results 1 to 11 of 11

Thread: tell-a-friend script and grabbing the title of a html-page

  1. #1
    Join Date
    Jan 2003
    Posts
    10

    tell-a-friend script and grabbing the title of a html-page

    I've done some small changes to a tell-a-friend script (http://folk.uio.no/leikh/nyheter/script/mailpage.pl ).

    First i took into account the help from javascript to read the url of a page in a second frame, and put this in a hidden form field, which then is read by the cgi-script.
    (this form is here: http://folk.uio.no/leikh/nyheter/tipsnyhet.html )

    (the actual stuff is at http://folk.uio.no/leikh/nyheter )


    I then wanted the title of the html-page (which is sent in the body of the mail) to be printed in the subject field of the mail.

    I added a use HTML::TokeParser; etc.....


    I get no error-messages, but i don't get the title in the subject either...


    But when i write the url directly into the $p = HTML::TokeParser->new(shift||"$FORM{'url'}"); , it works....

    i.e: $p = HTML::TokeParser->new(shift||"http://folk.uio.no/leikh/nyheter/www.uio.no/offentlig/news/messages/1100368.html");



    Anyone see what's wrong?

  2. #2
    Join Date
    Nov 2002
    Location
    NY, USA
    Posts
    731
    You aren't actually extracting any tokens yet.
    HTML::TokeParser

    $p->get_tag( [$tag, ...] )

    This method returns the next start or end tag (skipping any other tokens), or undef if there are no more tags in the document. If one or more arguments are given, then we skip tokens until one of the specified tag types is found. For example:

      $p->get_tag("font", "/font");

    will find the next start or end tag for a font-element.

    The tag information is returned as an array reference in the same form as for $p->get_token above, but the type code (first element) is missing. A start tag will be returned like this:

      [$tag, $attr, $attrseq, $text]

    The tagname of end tags are prefixed with "/", i.e. end tag is returned like this:

      ["/$tag", $text]
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

  3. #3
    Join Date
    Jan 2003
    Posts
    10
    hmmm.....
    did you bother to take at look at the script?
    http://folk.uio.no/leikh/nyheter/script/mailpage.pl

  4. #4
    Join Date
    Jan 2003
    Posts
    10
    well, some one just told me that

    "HTML::TokeParser->new() takes either a file name, file handle or a document. not a url"

    and that

    "you would presumably have to add the code to turn a url into html. e.g. with LWP::Simple"


    But how?

    I'm not skilled
    But i'm learing...

  5. #5
    Join Date
    Nov 2002
    Location
    NY, USA
    Posts
    731
    Sorry. I do see the problem now though.
    use HTML::TokeParser;
    $p = HTML::TokeParser->new(shift||"$FORM{'url'}");
    if ($p->get_tag("title")) {
    my $title = $p->get_trimmed_text;
    }
    You my() declare $title lexically scoped to inside the if block.

    my $title;
    if ($p->get_tag('title')) {
      $title = $p->get_trimmed_text();
    }


    And getting HTML

    use LWP::Simple;
    my $content = get('uri');
    if (!defined $content) {
      die 'Couldn't get it!';
    }
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

  6. #6
    Join Date
    Jan 2003
    Posts
    10
    i'm not following you...

    how is introducing $content without anything else gonna help me?

    and you write get('uri') . is this as in URI::URL?

    tried get('url'), but no...

    well, anyways - it's not working... not even after removing
    your single quote in "couldn't"

  7. #7
    Join Date
    Nov 2002
    Location
    NY, USA
    Posts
    731
    hooba
    how is introducing $content without anything else gonna help me?
    HTML::TokeParser will not accept a URI because it does not perform an HTTP request by itself. So we use LWP::Simple for the request, loaded into $content, and then provide a reference to that scalar for HTML::TokeParser.

    use HTML::TokeParser;
    use LWP::Simple;

    my $content = get('http://www.w3.org/');
    my $p = HTML::TokeParser->new(\$content);

    my $title;
    if ($p->get_tag('title')) {
      $title = $p->get_trimmed_text();
    }


    hooba
    tried get('url'), but no...
    That was an example, you do need to replace uri with an actual URI.

    get('http://www.w3.org/');

    hooba
    not even after removing your single quote in "couldn't"
    oops
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

  8. #8
    Join Date
    Jan 2003
    Posts
    10
    it's just that i don't know the url, and this is the essence of the problem... --> the url is posted by the form...

  9. #9
    Join Date
    Jan 2003
    Posts
    10
    this is what i've accomplished now
    http://folk.uio.no/leikh/nyheter/script/mailpage.pl

    but it's still not working...

    to test it, just go to http://folk.uio.no/leikh/nyheter
    and follow the 'tips en venn' in upper frame...

    If you fill out the form correctly, you'll get 'Ditt tips er sendt til:'


    /LH

  10. #10
    Join Date
    Nov 2002
    Location
    NY, USA
    Posts
    731
    First problem is that you are setting the value of $content after you use it for HTML::TokeParser. Second problem is that $title is still lexically scoped to only the if block.
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

  11. #11
    Join Date
    Jan 2003
    Posts
    10
    well, i've put it here and there and everywhere, but alli end up with is just getting even more confused...
    now it's more messy than ever...

    i give up.

    anyways, thx for your help

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles