机械化刮削方式2SMS

2024-09-30 01:31:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用刮刮方式2发送短信短信网,但我无法登录way2短信网使用mechanize。在

我使用以下代码提交登录表单。在

import mechanize
br = mechanize.Browser()
br.set_handle_robots(False)
br.set_handle_refresh(False)
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0')]
res=br.open('http://wwwa.way2sms.com/content/prehome.jsp')
link=list(br.links())[5]
res=br.follow_link(link)
br.form = list(br.forms())[0]
br.form.find_control('username').value=USERNAME    #user name
br.form.find_control('password').value=PASSWORD    #password
res=br.submit()

提交表单后,再次收到登录页面。在


Tags: brformfalse表单valuelinkrespassword
1条回答
网友
1楼 · 发布于 2024-09-30 01:31:27

只需将用户名和密码替换为用户名和密码。在

import mechanize
import cookielib
br = mechanize.Browser()

# Cookie Jar 
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)

# Browser options
br.set_handle_equiv(True) 
br.set_handle_gzip(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)

# Follows refresh 0 but not hangs on refresh > 0
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)

# User-Agent
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://site25.way2sms.com/content/index.html?'

#Opening WEbsite
op = br.open(url)

#Selection form
br.select_form(nr=0)

username = 'mobilenumberhere'
password = 'passwordhere'


#Give username and password
br.form['username'] = username
br.form['password'] = password

br.submit()


#To check whether log in Successful or not
if username in br.geturl():
     print "Login Failed" # Go to way2sms and enter wrong details. You will understand this.
else:
     print "Login Successful. You are at ", br.geturl()

相关问题 更多 >

    热门问题