Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

issue in perl script that sends sms using a third party website

by ramyavictor89 (Initiate)
on Feb 05, 2013 at 10:19 UTC ( #1017105=perlquestion: print w/replies, xml ) Need Help??
ramyavictor89 has asked for the wisdom of the Perl Monks concerning the following question:

I found a perl script that sends sms using a third party free website. It was working fine until today. Today i noticed that the "div tag id" used to get the access of the textbox to enter the sender's phone number is changed from static to dynamic, ie, the id is dynamically generated so i can no longer use the static id. I am using the WWW::Mechanize to access the forms,so can ou tell me how do i obtain a variable value that is dynamically generated in a webpage and use in my perl script. Here is the complete sample code that i am using:

#!/usr/bin/perl use WWW::Mechanize; use Compress::Zlib; my $mech = WWW::Mechanize->new(); my $username = ""; #fill in username registered here my $keyword = ""; #fill in password here my $opt="-f"; my ($text,$mobile,$option); my @mobilenos; my $morenos = $ARGV[0]; @mobilenos = $morenos; $text = $ARGV[1]; $deb = 1; print "Total Character of message is ".length($text)."\n" if($deb); $text = $text."\n\n\n\n\n" if(length($text) < 135); $mech->get(""); unless($mech->success()) { exit; } $dest = $mech->response->content; print "Fetching...\n" if($deb); if($mech->response->header("Content-Encoding") eq "gzip") { $dest = Compress::Zlib::memGunzip($dest); $mech->update_html($dest); } $dest =~ s/<form name="loginForm"/<form action='..\/Login1.action' nam +e="loginForm"/ig; $mech->update_html($dest); $mech->form_with_fields(("username","password")); $mech->field("username",$username); print "Loggin...\n" if($deb); $mech->submit_form(); $dest= $mech->response->content; if($mech->response->header("Content-Encoding") eq "gzip") { $dest = Compress::Zlib::memGunzip($dest); $mech->update_html($dest); } foreach $mobile (@mobilenos){ # for loop begins chomp($mobile); print "\nMessage sending to ".($mobile)."\n"; $mech->get(""); $dest= $mech->response->content; if($mech->response->header("Content-Encoding") eq "gzip") { $dest = Compress::Zlib::memGunzip($dest); $mech->update_html($dest); } print "Sending ... \n" if($deb); ####I AM UNABLE TO GET THE FORM WITH FIELD MobNo AS ITS rqMob WHOSE VA +LUE IS DYNAMICALLY GENERATED##### $mech->form_with_fields(("MobNo","textArea")); $mech->field("MobNo",$mobile); $mech->field("textArea",$text); $mech->submit_form(); if($mech->success()) { print "Done \n" if($deb); } else { print "Failed \n" if($deb); exit; } $dest = $mech->response->content; if($mech->response->header("Content-Encoding") eq "gzip") { $dest = Compress::Zlib::memGunzip($dest); #print $dest if($deb); } if($dest =~ m/successfully/sig) { print "Message sent successfully \n" if($deb); } # foreach loop ends } print "Message sent to all the numbers\n Bye.\n"; exit; #EOF
To run the script i type: ./ phone_number_of_reciever 'message_to_be_sent' . PLEASE HELP ME WITH THIS PROBLEM AS THIS IS A IMPORTANT PART OF MY PROJECT. THANKS IN ADVANCE..

Replies are listed 'Best First'.
Re: issue in perl script that sends sms using a third party website
by Corion (Pope) on Feb 05, 2013 at 10:37 UTC

    Have a look at WWW::Mechanize->forms, which will list all the available forms. From that, you can find the form with the fields you want to use. Maybe it is already enough to find the form that contains a field with the name textArea.

    It seems that way2sms also offers a better API where you can upload XML via FTP or HTTP instead of automating their website. Maybe you want to use that instead?

      can u be precise as to what u mean by uploading a xml?

        Why don't you read about their API, it has to tell you how to use it.

Re: issue in perl script that sends sms using a third party website
by roboticus (Chancellor) on Feb 05, 2013 at 10:41 UTC


    While it may be IMPORTANT PART OF YOUR PROJECT, it clearly violates the terms of use of the site. They make their money by selling advertisements on their site, which your users won't see. I'd suggest you instead look for the SMS gateways for the various phone networks you're trying to send messages to.


    When your only tool is a hammer, all problems look like your thumb.

Re: issue in perl script that sends sms using a third party website
by Anonymous Monk on Feb 05, 2013 at 11:12 UTC
    It's not a free website, you're breaking their terms of use and bypassing how they earn money to provide this service. In time this will make running the service unprofitable, and it'll shutdown. Your project is basically wrong if you're stupid enough to rely on automating someone elses service by making it difficult for them to support the service YOU depend on!
      My project is just a prototype and i am not coverting it to a product or use it forever. Thanks for our suggestion

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1017105]
Approved by vinoth.ree
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2016-09-29 21:50 GMT
Find Nodes?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:

    Results (561 votes). Check out past polls.