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

Open file and formfill

by fame (Initiate)
on Apr 26, 2012 at 02:26 UTC ( [id://967217]=perlquestion: print w/replies, xml ) Need Help??

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

I have a question.. I have perl bot thats uses IRC. One of the functions that I have it do upon a command is it opens a file with random emails and fills the form on a website.

This is how I have it read the file and select a random line.

open FILE, "emails.txt" or die "Error Opening: Cannot open file!"; @emails = <FILE>; close FILE; $email = $emails[int(rand($#emails + 1))];

This is how I have it form fill.

my $agent = WWW::Mechanize->new( autocheck => 1 ); my $formfiller = WWW::Mechanize::FormFiller->new(); $agent->env_proxy(); $agent->get('http://www.somewebsite.com'); $agent->form_number(2); $agent->current_form->value("email", "$email");

My problem is this: When it fills the form, it fills in the email address and the return html coding will look something like this:

name="email" id="email" value="blahblah@email.com

" size="35" maxlength="255" class="formFld" />

The email address is entered within the " " and then for some reason jumps to a next line like above. I need it for when it fills the form that it stays all on the same line within the " ". Example:

name="email" id="email" value="blahblah@email.com" size="35" maxlength="255" class="formFld" />

Does anyone have a solution for me? Any help would be GREATLY appreciated. Thanks

Replies are listed 'Best First'.
Re: Open file and formfill
by Anonymous Monk on Apr 26, 2012 at 04:07 UTC

    Hi,

    It looks like you've got some newlines in your $email. Check for this and, if they are there, remove them before proceeding.

    A simple regex should do the trick. I leave that to you.

    J.C.

      i solved problem with chomp();

      Thanks for your response J.C.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (9)
As of 2024-04-23 10:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found