weird issue with HTML::TokeParser and Fork

Discussion in 'Perl Misc' started by arik@blue-linedesign.com, May 4, 2008.

  1. Guest

    I wrote a script that scrape information off staples.com and I'm
    getting different results if I run it stand alone or I fork the
    script.
    running the script stand alone I get the expected results and when
    forking the script it seems like it ignores the <title> tag. any help
    is appreciated:
    this is part of the script:
    sub GetStaples {
    my $oem_PN = $_[0];
    my $ItemDesc = $_[1];
    my @ItemDesc = split(',',$ItemDesc);
    my $Item;
    my $price;
    my $description;
    my $type;
    my $title;
    my $numofitems;
    my $agent = WWW::Mechanize->new(autocheck => 1, cookie_jar =>
    undef);

    $agent->get("http://www.staples.com/webapp/wcs/stores/servlet/home?
    &langId=-1&storeId=10001&catalogId=10051");
    $agent->form_name("headerSearchForm");
    $agent->field("searchkey",$oem_PN);
    $agent->click();
    my $stream = HTML::TokeParser->new(\$agent->{content});

    open(OUTFILE, ">>output.html") or die "Can't open output.txt: $!";
    print OUTFILE $agent->content();
    close(OUTFILE);
    my $tag = $stream->get_tag("title");
    $title = $stream->get_trimmed_text("/title");
    print "Title:".$tile."\n";
    if ($title !~ /that was easy/){........................

    and this is how I fork the script

    $pidStaples=fork();
    die "Cannot fork: $!" if (! defined $pidStaples);
    if (not defined $pidStaples) {
    print "esources not avilable.\n";
    } elsif ($pidStaples == 0){

    GetStaples($ref->{OEM_PartNum},$ref->{Description});
    exit(0);
    }
    the parameters are being passed successfully
    and if you noticed I've created an outputfile.html to debug the agent-
    >content and it comes back as expected.

    even with that I can's get $title back
     
    , May 4, 2008
    #1
    1. Advertising

  2. Ben Bullock Guest

    On Sat, 03 May 2008 16:58:46 -0700, arik wrote:

    > $title = $stream->get_trimmed_text("/title");

    ^^^^^^
    > print "Title:".$tile."\n";

    ^^^^^
    use warnings;
    use strict;
     
    Ben Bullock, May 4, 2008
    #2
    1. Advertising

  3. Bart Lateur Guest

    Ben Bullock wrote:

    >On Sat, 03 May 2008 16:58:46 -0700, arik wrote:
    >
    >> $title = $stream->get_trimmed_text("/title");

    > ^^^^^^
    >> print "Title:".$tile."\n";

    > ^^^^^
    >use warnings;
    >use strict;


    This guy posted the exact same question on Perlmonks, and,
    unsurprisingly, got the exact same reply (second rekly, by ikegami).

    http://perlmonks.org/?node_id=684388

    I hate it when people are multiposting the same question all over, and
    are simply not paying attention to the replies.

    --
    Bart.
     
    Bart Lateur, May 5, 2008
    #3
  4. Ben Bullock Guest

    On Mon, 05 May 2008 20:50:23 +0200, Bart Lateur wrote:

    > This guy posted the exact same question on Perlmonks, and,
    > unsurprisingly, got the exact same reply (second rekly, by ikegami).
    >
    > http://perlmonks.org/?node_id=684388
    >
    > I hate it when people are multiposting the same question all over, and
    > are simply not paying attention to the replies.


    According to the times on the posts, arik / arikamir posted his question
    here via Google Groups at about 12.00 midnight UTC (17.00 his time), then
    got an answer from me twenty minutes later (9.20 in the morning my time),
    then three and a half hours after I'd posted an answer, apparently
    ignoring the answer I'd posted, he went to Perl monks and posted the same
    question there.
     
    Ben Bullock, May 6, 2008
    #4
  5. Guest

    On May 5, 5:25 pm, Ben Bullock <> wrote:
    > On Mon, 05 May 2008 20:50:23 +0200, Bart Lateur wrote:
    > > This guy posted the exact same question on Perlmonks, and,
    > > unsurprisingly, got the exact same reply (second rekly, by ikegami).

    >
    > > http://perlmonks.org/?node_id=684388

    >
    > > I hate it when people are multiposting the same question all over, and
    > > are simply not paying attention to the replies.

    >
    > According to the times on the posts, arik / arikamir posted his question
    > here via Google Groups at about 12.00 midnight UTC (17.00 his time), then
    > got an answer from me twenty minutes later (9.20 in the morning my time),
    > then three and a half hours after I'd posted an answer, apparently
    > ignoring the answer I'd posted, he went to Perl monks and posted the same
    > question there.


    I apologies for this, however I received the answer from the monks
    before I received the answer here
    in any case thank you all very much for taking the time and answering
    the question.

    I eager to get to a point that I can contribute as well.

    Arik
     
    , May 6, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick Joly
    Replies:
    0
    Views:
    97
    Patrick Joly
    Feb 25, 2004
  2. Maqo
    Replies:
    4
    Views:
    149
    A. Sinan Unur
    Feb 23, 2005
  3. jussi
    Replies:
    3
    Views:
    142
    Sherm Pendley
    Oct 7, 2005
  4. DVH

    HTML::TokeParser

    DVH, Oct 16, 2005, in forum: Perl Misc
    Replies:
    8
    Views:
    121
    A. Sinan Unur
    Oct 19, 2005
  5. Abram

    HTML::TokeParser & TableExtract

    Abram, Apr 25, 2006, in forum: Perl Misc
    Replies:
    16
    Views:
    227
    David Combs
    May 22, 2006
Loading...

Share This Page