当前位置: 首页>>代码示例>>Python>>正文


Python Browser.form['duration']方法代码示例

本文整理汇总了Python中mechanize.Browser.form['duration']方法的典型用法代码示例。如果您正苦于以下问题:Python Browser.form['duration']方法的具体用法?Python Browser.form['duration']怎么用?Python Browser.form['duration']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mechanize.Browser的用法示例。


在下文中一共展示了Browser.form['duration']方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: day

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import form['duration'] [as 别名]
  </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> 
'''

resp.set_data( response )
br.set_response( resp )

# Filling the form using the response
br.select_form( nr = 0 )

# Set 1 for one hour and 2 for one day
br.form[ 'duration' ] = [ '2' ]
response = br.submit()
print "I put your Netaccess"
开发者ID:ashutoshkrjha,项目名称:Netaccess-Putter,代码行数:32,代码来源:netaccessiitm.py

示例2: login

# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import form['duration'] [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()
开发者ID:kevinselvaprasanna,项目名称:netaccess-indicator,代码行数:70,代码来源:netaccess-indicator.py


注:本文中的mechanize.Browser.form['duration']方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。