我正在尝试使用wayssms使用mechanize python发送消息。提交发送时。我一无所获。
即使我编辑了msgLen = 135(message ='hello')字符,
br.submit()也无法正常工作。
我正在上传可能对您有帮助的篡改数据屏幕截图和livehttp标题。
答案 0 :(得分:2)
我希望你发现这个有用我编写的以下代码发送短信,这对我来说很好 完整的详细解决方案可在我的博客http://rishabhroy.blogspot.in/2015/08/automate-sms-using-way2smspy.html上找到 只需用您的用户名和密码替换用户名和密码即可。 import urllib2
import cookielib
from getpass import getpass
import sys
username= ''
passwd=''
message=raw_input("messge")
number=raw_input("number")
message="+".join(message.split(' '))
url= 'http://site21.way2sms.com/Login1.action'
data = 'username='+username+'&password='+passwd
cj =cookielib.CookieJar()
opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
opener.addheaders=[('User-Agent',"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36")]
try:
usock = opener.open(url,data)
except IOError:
print "cannot connect "
sys.exit(1)
jession_id=str(cj).split('~')[1].split(' ')[0]
print jession_id
p= opener.open("http://site21.way2sms.com/ebrdg.action?id="+jession_id)
send_sms_url='http://site21.way2sms.com/smstoss.action'
send_sms_data= 'ssaction=ss&Token='+jession_id+'&mobile='+number+'&message='+message+'&msgLen='+str(140-len(message))
opener.addheaders=[('Referer','http://site21.way2sms.com/sendSms?Token='+jession_id)]
#opener.addheaders=[('Host','site21.way2sms.com')]
#try:
sms_sent_page = opener.open(send_sms_url,send_sms_data)
#except IOError as e :
# print e
opener.open('http://site21.way2sms.com/smscofirm.action?SentMessage='+message+'&Token='+jession_id+'&status=0')
答案 1 :(得分:1)
我们需要打开表单然后我们必须修复以便发送提交表单。直接提交在这里不起作用,因为它使用JavaScript。
br.select_form(nr=0)
br.form.set_all_readonly(False)
message += ' ' * (140 - len(message))
br.form['mobile'] = mobile
br.form['message'] = message
br.form['msgLen'] = str(140)
br.form.method = 'POST'
sendurl = 'http://site23.way2sms.com/smstoss.action'
br.form.action = sendurl
br.form.fixup()
res = br.submit()
所以,最后总结所有代码......!
import sys
import time
import os
import mechanize
import cookielib
from getpass import getpass
br = mechanize.Browser()
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
br.set_handle_equiv(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
br.addheaders = [('User-agent',
'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
url = 'http://site23.way2sms.com/content/index.html?'
op = br.open(url)
br.select_form(nr=0)
stamp = "\n +=======================================+\n |..........Way2SMS Msg Tool v 1.........|\n +---------------------------------------+\n |#Author: 7H3 !N5|D3R |\n |#Contact: www.fb.com/Gowtham95india |\n |#Date: 10/09/2014 |\n |#This tool is made for pentesting. |\n |#Changing the Description of this tool |\n |Won't make you the coder ^_^ !!! |\n |#Respect Coderz Plz ^_^ |\n |#I Take No Responsibilities For The |\n | Use Of This Program ! |\n +=======================================+\n |......... Way2SMS Automation .........|\n +---------------------------------------+\n"
print stamp
username = raw_input('Mobile Number:')
password = getpass('Password:')
token = ''
def login():
global username
global token
global password
br.select_form(nr=1)
br.form['username'] = username
br.form['password'] = password
br.submit()
a = br.geturl()
if username in br.geturl():
print "[-] Login Failed."
time.sleep(3)
print "[-] Exiting Now..."
time.sleep(3)
os.system('clear')
sys.exit()
return False
else:
i = a.index('=')
j = a.index('?')
token = a[i + 1:j]
return token
def send(mobile, message):
smsurl = 'http://site23.way2sms.com/sendSMS?Token=' + token
br.open(smsurl)
br.addheaders = [('User-agent',
'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1'),
('Referer', 'http://site25.way2sms.com/sendSMS?Token=' + token)]
br.select_form(nr=0)
br.form.set_all_readonly(False)
message += ' ' * (140 - len(message))
br.form['mobile'] = mobile
br.form['message'] = message
br.form['msgLen'] = str(140)
br.form.method = 'POST'
sendurl = 'http://site23.way2sms.com/smstoss.action'
br.form.action = sendurl
br.form.fixup()
res = br.submit()
if 'status=0' in br.geturl():
return True
else:
return False
if __name__ == '__main__':
send(raw_input("Enter recpt: "),raw_input("Enter Msg: "))