CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
VoipDiscount phone-to-phone

 



yuriy
Novice

Jan 24, 2010, 9:00 AM

Post #1 of 6 (858 views)
VoipDiscount phone-to-phone Can't Post

  Hello perl gurus,

i am completely new to perl, never worked with it and probably never will. However, as far as i understand, perl is quite useful if ones wants to write a script which automates some actions in WWW.

The problem is the following. For my foreign calls I use software called Voipdiscount. It is basically just yet another one SIP-service, but they have a neat function which is called "phone-to-phone": first your number is dialed and when you pick up, then the destination number. I use this function quite often, because I don't want to stick at my computer with a headset on my head.

Now, Voipdiscount provides only a Windows version of their software, however, for Mac and Linux users (I belong to the latter) the whole functionality is available on their website. Being too lazy to log myself in and enter the phone numbers manually, I would like to have a script that would do the job for me.

After a half an hour of googling, I came up with the following code:


Code
#!/usr/bin/perl -w 

`perl -MLWP::Simple -e "getprint 'https://www.voipdiscount.com/myaccount/phone-to-phone.php?username=user&password=pass&from=myphone&to=destphone'" > /dev/null 2>&1`;


Of course, I replace user, pass, myphone and destphone with the corresponding values. Now, this script seems to be running without any errors, but it also doesn't work.

I tested the URL. If I open it with my browser before logging in, it will redirect me to a login page, even though I've already specified the user name and the password in the URL. If I have already logged in, then the correct page is opened and the phone number fields are filled with correct numbers, but nothing more happens.

There is a button called "Call now" which has to be clicked on to make a call. So the question is, how can I make the perl script "click the button" for me.

I don't know whether this question relates to perl or to php (or both), so excuse me, if this is the wrong place to post this question. But in any case, any help will be greatly appreciated.


FishMonger
Veteran / Moderator

Jan 24, 2010, 9:41 AM

Post #2 of 6 (855 views)
Re: [yuriy] VoipDiscount phone-to-phone [In reply to] Can't Post

Instead of LWP::Simple, you need to use WWW::Mechanize

http://search.cpan.org/~petdance/WWW-Mechanize-1.60/lib/WWW/Mechanize.pm

http://search.cpan.org/~petdance/WWW-Mechanize-1.60/lib/WWW/Mechanize/FAQ.pod


yuriy
Novice

Jan 24, 2010, 10:44 AM

Post #3 of 6 (852 views)
Re: [FishMonger] VoipDiscount phone-to-phone [In reply to] Can't Post

Seems that I really will have to learn at least a bit of perl and of WWW:Mechanize. Well, thank you, I will try to figure something out.


yuriy
Novice

Jan 24, 2010, 11:46 AM

Post #4 of 6 (850 views)
Re: [yuriy] VoipDiscount phone-to-phone [In reply to] Can't Post

I am currently struggling with WWW:Mechanize. I've got so far:

Code
#!/usr/bin/perl -w 

# Include needed modules
use WWW::Mechanize;

# Create a Mechanize object
my $mech = WWW::Mechanize->new( agent => 'ph2ph 0.01a' );

# Set alias to Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
# Dunno if I really need this :)
$mech->agent_alias( 'Windows IE 6' );

# URI of the main account page
$u1 = URI->new("https://www.voipdiscount.com/myaccount/");

# Fetch the main account page
$mech->get($u1);

# Use the first form for further calls
$mech->form_number(1);


Now, I have been reading [url=http://search.cpan.org/~petdance/WWW-Mechanize-1.60/lib/WWW/Mechanize.pm#$mech->field(_$name,_$value,_$number_)]this, but all the methods listed there assume that I know the names of the fields. Is there a way to list the names of the fields so that a) I would know them, b) I could check that I'm on the right way.

Thanks in advance!


yuriy
Novice

Jan 24, 2010, 11:51 AM

Post #5 of 6 (848 views)
Re: [yuriy] VoipDiscount phone-to-phone [In reply to] Can't Post

Ok, got that, I can list them with

Code
$mech->dump_forms();


Sorry to have bothered :)


yuriy
Novice

Jan 24, 2010, 12:27 PM

Post #6 of 6 (843 views)
Re: [yuriy] VoipDiscount phone-to-phone [In reply to] Can't Post

All right, thanks for the great advice!!! It all works now. For the case someone's interested, here it is, my first humble perl creation:


Code
#!/usr/bin/perl -w 

# Include needed modules
use WWW::Mechanize;

# Create a Mechanize object
$mech = WWW::Mechanize->new( agent => 'ph2ph 0.01a' );

# Set alias to Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
# Dunno if I really need this :)
$mech->agent_alias( 'Windows IE 6' );

# URI of the main account page
$u1 = URI->new("https://www.voipdiscount.com/myaccount/index.php");

# Fetch the main account page
$mech->get($u1);

# Use the first form for further calls
$mech->form_number(1);

# Send user name and password (replace the field values with your account data)
$mech->set_fields('username' => 'username', 'password' => 'password');

# Submit the login form
$mech->submit();

# URI of the phone-to-phone page
$u2 = URI->new("https://www.voipdiscount.com/myaccount/phone-to-phone.php");

# Fetch the phone-to-phone page
$mech->get($u2);

# Use the first form for further calls
$mech->form_number(1);

# Send phone numbers (replace field values with phone numbers in international format)
$mech->set_fields('anrphonenr' => 'number1', 'bnrphonenr' => 'number2');

# Make a call
$mech->click();


Thanks again!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives