How To Create Way2sms Sms Sending Script Using python mechanize module - Web Scraping - part 10

Hello Friends,


                           This is our 10th part of web scraping tutorials. and in this tutorial, I am gonna to show you how to create python script for sending sms automatically using way2sms services and for this purpose we will use mechanize python module . but first, if you are new visitor then first check our index or For 9th Part Click Here

So,  Let's Talk About Today's Topic,

Q 1. Purpose of Python Mechanize Module

Ans. In Simple Words, it gives you a browser like object to interact with website. For More Info. Check here  http://stockrt.github.com .

This Python Script will act like a interface between user and way2sms website. with this script, we can send messages without opening way2sms website in browser.

So, Let's Start.
Here, I am Sharing My Demo Codes But If You Want More Better Example Then, You Can Modify these codes yourself or Download This Script From My GitHub repository (link given at the end of these codes ).

 1. way2sms[mechanize].py

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
#!/usr/bin/python
# ---------------- READ ME ---------------------------------------------
# This Script is Created Only For Practise And Educational Purpose Only
# This Script Is Created For https://bitforestinfo.blogspot.in
# This Script is Written By
__author__='''

######################################################
                By S.S.B Group                          
######################################################

    Suraj Singh
    Admin
    S.S.B Group
    surajsinghbisht054@gmail.com
    https://bitforestinfo.blogspot.in/

    Note: We Feel Proud To Be Indian
######################################################
'''
# Import Module
import mechanize
import cookielib
import sys

# Function For Extracting Tokken 
def cook(cj):
 j=str(cj)
 t2=j.find(' for ')
 t1=int(j.find('~'))+1
 tokken=str(j[t1:t2])
 return tokken 

# Main Function
def main():
 number=int(raw_input(' [+] Please Enter Your Username : '))
        password=int(raw_input(' [+] Please Enter Your Password : '))
 #================   Checking Mechanizam =====================================
 if len(str(number))==10:
  pass
 else:
  print " [*] Invalid Username"
  sys.exit(0)
 if len(str(password))==10:
  pass
 else:
  print " [*] Invalid Password  "
  sys.exit(0)


 #============================================================================
 # ***************** Login *******************************
 # ***************** Configuration  ********************** 
 url='http://site24.way2sms.com/Login1.action'
 data='username='+str(number)+'&password='+str(password)
 # ********************************************************
 cj=cookielib.LWPCookieJar()
 br=mechanize.Browser()
 br.addheaders=[('User-Agent', 'Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0 Iceweasel/31.8.0')]
 # Setting Management
 br.set_cookiejar(cj)
 br.set_debug_http(True)
 br.set_debug_redirects(True)
 br.set_debug_responses(True)
 br.set_handle_equiv(True)
 br.set_handle_redirect(True)
 br.set_handle_referer(True)
 print '[+] Please Wait. Trying To Login In '
 req=br.open(url, data=data)
 print '\n'*14,'[+] Login Successful [+]'
 # ****** Tokken Receiving Mechanizem ******************
 tokken=cook(cj)
 print '\n [+] Tokken Received : ', tokken
 # *******************************************************************
 # ********* Sms Sending System Configuration ************************
 url='http://site24.way2sms.com/smstoss.action'
 head=[('User-Agent','Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0 Iceweasel/31.8.0'),('Refere','http://site24.way2sms.com/sendSMS?Token='+tokken)]
 mobile=int(raw_input(' [*] Please Enter Mobile Number For Sending SMS : '))
 #================   Checking Mechanizam =====================================
 if len(str(mobile))==10:
  pass
 else:
  print " [*] Invalid Username"
  sys.exit(0)


 while True:
  message_raw=str(raw_input(' [*] Please Enter Message For Sending. Note ! Not More Then 140 Words: '))
  message=message_raw.replace(' ', '+')
  msglen=140-len(message)
  if len(message)<140:
   break
  else:
   pass
 data='ssaction=ss&Token='+tokken+'&mobile='+str(mobile)+'&message='+str(message)+'&msgLen='+str(msglen)
 br.addheaders=head
 print '[+] Sending SMS . Please Wait [+]'
 req=br.open(url, data=data)
 print '\n'*40,' [+] Task Complete Thanks For Using [+]'

# Main Function Trigger
if __name__=='__main__':
 main()

Warning I am Creating This Tutorial Only For Practise and Educational Purpose. I will not Take any type of responsibility about any illegal activities.

For Downloading, Raw Script Click Here



For More Update, Visit Our Regularly. 
And Subscribe Our Blog, 

Follow Us and share it.
For Any Type of Suggestion Or Help
Contact me:
S.S.B
surajsinghbisht054@gmail.com


Share this

Related Posts

Previous
Next Post »