本文整理汇总了Python中mechanize.Browser.form["userPassword"]方法的典型用法代码示例。如果您正苦于以下问题:Python Browser.form["userPassword"]方法的具体用法?Python Browser.form["userPassword"]怎么用?Python Browser.form["userPassword"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mechanize.Browser
的用法示例。
在下文中一共展示了Browser.form["userPassword"]方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Browser
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import form["userPassword"] [as 别名]
import urllib2
roll = ""
password= ""
# New browser object
br = Browser()
# Open Login page
print "Logging in"
page = br.open( 'https://netaccess.iitm.ac.in/account/login' )
br.select_form( nr = 0 )
# Fill in the fields
br.form[ "userLogin" ] = roll
br.form[ "userPassword" ] = password
# Submit to login
br.submit()
print "Approving your IP"
# Directly go to the approve page. Cookies taken care of by Mechanize browser
resp = br.open( 'https://netaccess.iitm.ac.in/account/approve' )
# Hardcoded response due to bad HTML on site
hardcoded_resp = '''
<form class="form-horizontal" method="post" action="/account/approve">
<fieldset>
<!-- Form Name -->
<legend>Authorization</legend>
<!-- Multiple Radios -->
示例2: Browser
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import form["userPassword"] [as 别名]
from mechanize import Browser
import urllib2
br = Browser()
# Going to the login page
page = br.open( 'https://netaccess.iitm.ac.in/account/login' )
br.select_form( nr = 0 )
# Replace with your LDAP username and password
br.form[ "userLogin" ] = "PUT_USERNAME_HERE"
br.form[ "userPassword" ] = "PUT_PASSWORD_HERE"
br.submit()
resp = br.open( 'https://netaccess.iitm.ac.in/account/approve' )
response = '''
<form class="form-horizontal" method="post" action="/account/approve">
<fieldset>
<!-- Form Name -->
<legend>Authorization</legend>
<!-- Multiple Radios -->
<div class="form-group">
<label class="col-md-4 control-label" for="radios">Duration</label>
<div class="col-md-4">
<div class="radio">
<label for="radios-0">
<input type="radio" name="duration" id="radios-0" value="1" checked="checked">
60 minutes (recommended for public machines)
</label>
</div>
<div class="radio">
示例3: login
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import form["userPassword"] [as 别名]
def login(roll, password):
# New browser object
br = Browser()
#Open Login page
print "Logging in"
page = br.open( 'https://netaccess.iitm.ac.in/account/login' )
br.select_form( nr = 0 )
# Fill in the fields
br.form[ "userLogin" ] = roll
br.form[ "userPassword" ] = password
# Submit to login
br.submit()
print "Approving your IP"
# Directly go to the approve page. Cookies taken care of by Mechanize browser
resp = br.open( 'https://netaccess.iitm.ac.in/account/approve' )
# Hardcoded response due to bad HTML on site
hardcoded_resp = '''
<form class="form-horizontal" method="post" action="/account/approve">
<fieldset>
<!-- Form Name -->
<legend>Authorization</legend>
<!-- Multiple Radios -->
<div class="form-group">
<label class="col-md-4 control-label" for="radios">Duration</label>
<div class="col-md-4">
<div class="radio">
<label for="radios-0">
<input type="radio" name="duration" id="radios-0" value="1" checked="checked">
60 minutes (recommended for public machines)
</label>
</div>
<div class="radio">
<label for="radios-1">
<input type="radio" name="duration" id="radios-1" value="2">
1 day (hostel zone)
</label>
</div>
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="approveBtn"></label>
<div class="col-md-4">
<button id="approveBtn" name="approveBtn" class="btn btn-primary">Authorize</button>
</div>
</div>
</fieldset>
</form>
'''
# Setting response for Page as the hardcoded response.
resp.set_data( hardcoded_resp )
br.set_response( resp )
# Filling the form using the hardcoded response
br.select_form( nr = 0 )
# Set duration as 1 for one hour and 2 for one day
br.form[ 'duration' ] = [ '2' ]
response = br.submit()
print "Logged in"
f = open('/home/kevinselvaprasanna/netaccess-indicator/netaccess.html', 'w')
f.write(response.read())
f.close()