Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

[Click the star to watch this topic] weird issue with HTML::TokeParser and Fork

by arikamir (Initiate)
on May 04, 2008 at 03:49 UTC ( [id://684388]=perlquestion: print w/replies, xml ) Need Help??

arikamir has asked for the wisdom of the Perl Monks concerning the following question:

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, cooki +e_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 out +put.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 (! de +fined $pidStaples); if (not defined $pidStaples) { print "esources not av +ilable.\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 04, 2008 at 17:17 UTC Janitored by McDarren: Added code tags

Replies are listed 'Best First'.
Re: weird issue with HTML::TokeParser and Fork
by ikegami (Patriarch) on May 04, 2008 at 06:51 UTC
    print "Title:".$tile."\n" ^^^^^

    How come you're not using use strict;?

    What does "it ignores the <title> tag" mean?

      I used it when I developed the script and then it gave me warning while running it. in any case I reinstated strict which solved this issue. I do have have another issue (which hopefully will be as easy to solve), I have four scripts that are very similar, one for staples one for buy.com one for office depot and one for amazon. each one search for a product and insert the results to a mysql table. when I fork the process they all seem to insert the results to the same table although I open a database connection in each script after it has been forked and the sql insert statement is directed to the correct table. can you please point me to the correct documentation? thanks a lot for your help
        Sounds right. We'd have to see the code to know what the problem was.
Re: [Click the star to watch this topic] weird issue with HTML::TokeParser and Fork
by Anonymous Monk on May 04, 2008 at 05:28 UTC
weird issue with HTML::TokeParser and Fork
by BKB (Novice) on May 06, 2008 at 00:39 UTC
    Your question was already answered on comp.lang.perl.misc before you posted this to Perlmonks. If you're going to post a question to the newsgroup, would you mind taking the trouble to actually read the answers? Thanks.
      I've posted an apology on comp.lang.perl.misc it seems like when you refrech this thread you can immediately see what people responded, which makes life much easier. never the less I humbly thank all those who take the time to answer.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://684388]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-03-19 02:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found