Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

nested loop within Mechanize

by Perlbeginner1 (Scribe)
on Oct 03, 2012 at 17:59 UTC ( #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
Node Status?
node history
Node Type: perlquestion [id://997112]
Approved by Corion
help
Chatterbox?
[zentara]: more like Dr. Helion3 :-)
[LanX]: Eily: though I haven't found a a reference for this one yet : Re^2: OT: Got fired this week (orange)
LanX googling for ones own childish humour has advantages ... see Pray for Paris

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (14)
As of 2017-03-27 15:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (320 votes). Check out past polls.