Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

nested loop within Mechanize

by Perlbeginner1 (Scribe)
on Oct 03, 2012 at 17:59 UTC ( [id://997112]=perlquestion: print w/replies, xml ) Need Help??

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

hello monks :)

it's waaay too long i haven't been coding (at all), and especially coding in perl, so please forgive me for this dumb dumb dumb question.

I haven't found it answered, so either I can't even properly search or it's so dumb nobody ever dared to ask. my need : I've got two arrays, say

Well i am currently working on a small solution: I have tried various tutorials (examples of Mecha - that i have found on the net) not oll of them work - some of them are broken!

Now i try to get some real-world-task! This is much more interesting for me as a Perl-beginner
i start with a Mechanize-job, which sure can be done with LWP too. But at the beginning i want to keep it pretty simple. Well i need Mecha - particularly for doing the form based search and selecting the individual entries.

goal: i have approximatley 100 pages to parse
they are organized like that:

http://www.address/307.html http://www.address/308.html http://www.address/309.html


Hmm - i guess that the algorithm would be basically only one nested loop: hmm - one outer loop runs the form based search, and yes: one inner loop processes the search results.

well i did it like this one here:

use WWW::Mechanize; my $mech = WWW::Mechanize->new(); my $url = "here the urls go in "; $mech->cookie_jar->set_cookie(0,"start",1,"/",".test.com"); $mech->get($url);


It's really really !!! just one loop, isn't it?

foreach my $url (@urls) { my $response = $ua->post($url, \%data); my $result = parse_response($response); }


well the thing is pretty simple - i need to do two things with Mechanize
- particularly for doing the form based search and
- selecting the individual entries and parse them


well what do you say?!

Replies are listed 'Best First'.
Re: nested loop within Mechanize
by Anonymous Monk on Oct 03, 2012 at 18:57 UTC
      Hi there -
      well the question is - should i output the results to the screen or can i create a csv result

        Doesn't the form of your output (screen|csv|other) depend upon the purpose of your parsing the approximately 100 pages?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://997112]
Approved by Corion
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: (3)
As of 2024-04-19 21:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found