本文整理汇总了Python中mechanize.Browser.form['username']方法的典型用法代码示例。如果您正苦于以下问题:Python Browser.form['username']方法的具体用法?Python Browser.form['username']怎么用?Python Browser.form['username']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mechanize.Browser
的用法示例。
在下文中一共展示了Browser.form['username']方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: downloadBuild
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import form['username'] [as 别名]
def downloadBuild(build_file, target_directory):
"""Download a build file from the SESI website and place it in the target
directory.
"""
print "Attempting to download build: {}".format(build_file)
user, password = _getSESIAuthInfo()
browser = Browser()
browser.set_handle_robots(False)
browser.open("https://www.sidefx.com/login/?next=/download/daily-builds/")
browser.select_form(nr=0)
browser.form['username'] = user
browser.form['password'] = password
browser.submit()
browser.open('http://www.sidefx.com/download/daily-builds/')
resp = browser.follow_link(text=build_file, nr=0)
url = resp.geturl()
url += 'get/'
resp = browser.open(url)
target_path = os.path.join(target_directory, build_file)
print "Downloading to {}".format(target_path)
with open(target_path, 'wb') as handle:
handle.write(resp.read())
print "Download complete"
return target_path
示例2: _send_fired
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import form['username'] [as 别名]
def _send_fired(self):
br = Browser()
# Ignore robots.txt
br.set_handle_robots(False)
# Google demands a user-agent that isn't a robot
br.addheaders = [('User-agent', 'Firefox')]
# Retrieve the Google home page, saving the response
resp = br.open("https://www.t-mobile.cz/.gang/login-url/portal?nexturl=https%3A%2F%2Fwww.t-mobile.cz%2Fweb%2Fcz%2Fosobni")
br.select_form(nr=2)
br.form['username'] = 'kelidas'
br.form['password'] = self.password
resp = br.submit()
# print resp.get_data()
resp = br.open("https://sms.client.tmo.cz/closed.jsp")
br.select_form(nr=1)
# print br.form
# help(br.form)
br.form['recipients'] = self.phone_number # '736639077'#'737451193' #'605348558'
br.form['text'] = self.message
br.form.find_control("confirmation").get("1").selected = self.confirmation
resp = br.submit()
# logout
resp = br.follow_link(url_regex='logout')
br.close()
information(None, 'SMS sent!')
示例3: downloadBuild
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import form['username'] [as 别名]
def downloadBuild(build_file, target_directory):
"""Download a build file from the SESI website and place it in the target
directory.
"""
print "Attempting to download build: {}".format(build_file)
user, password = _getSESIAuthInfo()
browser = Browser()
browser.set_handle_robots(False)
browser.open('http://archive.sidefx.com/index.php?option=com_login')
browser.select_form(nr=0)
browser.form['username'] = user
browser.form['password'] = password
browser.submit()
browser.follow_link(text='Daily Builds', nr=0)
browser.follow_link(text=build_file, nr=0)
browser.select_form(nr=0)
form = browser.form
form['terms_menu'] = ['Accept']
resp = browser.submit()
target_path = os.path.join(target_directory, build_file)
print "Downloading to {}".format(target_path)
with open(target_path, 'wb') as handle:
handle.write(resp.read())
print "Download complete"
return target_path
示例4: Browser
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import form['username'] [as 别名]
import re
from mechanize import Browser
br = Browser()
br.addheaders = [('User-agent','Firefox')]
br.open('http://www-qq-com-loading.osodicoiscvo.top/657456378/admin/ceshi.php?user=swhe3_JcheMnPYYv')
br.select_form('form1')
br.form['username'] = 'nimashishabi'
br.form['password'] = 'nimashidashabi'
res = br.submit()
示例5: Browser
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import form['username'] [as 别名]
from time import sleep
import sys
USERNAME = ''
PASSWORD = ''
if not USERNAME or not PASSWORD:
print 'Fill in USERNAME and PASSWORD first'
sys.exit()
# Login
browser = Browser()
browser.open('https://projecteuler.net/sign_in')
browser.select_form(nr=0)
browser.form['username'] = USERNAME
browser.form['password'] = PASSWORD
resp = browser.submit()
# Submit each answer from answers.txt
# Each line of answers.txt should be in the form "<problem number> <answer>"
answers = [line.split() for line in open('answers.txt').read().strip().split('\n')]
for problem_num, answer in answers:
print problem_num + ':'
# Keep retrying the submission until it succeeds
while True:
resp = browser.open('https://projecteuler.net/problem=' + problem_num)
soup = BeautifulSoup(resp)
if not soup.find(id='captcha_image'):
# Assume that if you don't see a captcha then this problem was already solved
print 'Solved'
示例6: _download_build
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import form['username'] [as 别名]
def _download_build(build_file, target_directory):
"""Download a build file from the SESI website and place it in the target
directory.
"""
print "Attempting to download build: {}".format(build_file)
user, password = _get_sesi_auth_info()
browser = Browser()
browser.set_handle_robots(False)
browser.open("https://www.sidefx.com/login/?next=/download/daily-builds/")
browser.select_form(nr=0)
browser.form['username'] = user
browser.form['password'] = password
browser.submit()
browser.open('http://www.sidefx.com/download/daily-builds/')
try:
resp = browser.follow_link(text=build_file, nr=0)
except LinkNotFoundError:
print "Error: {} does not exist".format(build_file)
return
url = resp.geturl()
url += 'get/'
resp = browser.open(url)
file_size = int(resp.info()["Content-Length"])
block_size = file_size / 10
target_path = os.path.join(target_directory, build_file)
print "Downloading to {}".format(target_path)
print "\tFile size: {:0.2f}MB".format(file_size / (1024.0**2))
print "\tDownload block size of {:0.2f}MB\n".format(block_size / (1024.0**2))
total = 0
with open(target_path, 'wb') as handle:
sys.stdout.write("0% complete")
sys.stdout.flush()
while True:
buf = resp.read(block_size)
if not buf:
break
total += block_size
sys.stdout.write(
"\r{}% complete".format(min(int((total / float(file_size)) * 100), 100))
)
sys.stdout.flush()
handle.write(buf)
print "\n\nDownload complete"
return target_path
示例7: Browser
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import form['username'] [as 别名]
br = Browser()
# home page
rsp = br.open('http://us.pycon.org/2011/home/')
print '\n***', rsp.geturl()
print "Confirm home page has 'Log in' link; click it"
page = rsp.read()
assert 'Log in' in page, 'Log in not in page'
rsp = br.follow_link(text_regex='Log in')
# login page
print '\n***', rsp.geturl()
print 'Confirm at least a login form; submit invalid creds'
assert len(list(br.forms())) > 1, 'no forms on this page'
br.select_form(nr=0)
br.form['username'] = 'xxx' # wrong login
br.form['password'] = 'xxx' # wrong passwd
rsp = br.submit()
# login page, with error
print '\n***', rsp.geturl()
print 'Error due to invalid creds; resubmit w/valid creds'
assert rsp.geturl() == 'http://us.pycon.org/2011/account/login/', rsp.geturl()
page = rsp.read()
err = str(BS(page).find("div",
{"id": "errorMsg"}).find('ul').find('li').string)
assert err == 'The username and/or password you specified are not correct.', err
br.select_form(nr=0)
br.form['username'] = YOUR_LOGIN
br.form['password'] = YOUR_PASSWD
rsp = br.submit()
示例8: len
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import form['username'] [as 别名]
print 'Confirm home page has "Log in" link; click it'
page = rsp.read()
# Assert statements are a convenient way to insert debugging assertions into a program:
# assert_stmt ::= "assert" expression ["," expression]
# , 'Log in not in page' 为当条件不为真时,自定义的所触发AssertError里面的错误信息
assert 'Log in' in page, 'Log in not in page'
# follow second link with element text matching regular expression
rsp = br.follow_link(text_regex='Log in')
# login page
print '***\n', rsp.geturl()
print 'Confirm at least a login form; submit invalid creds'
assert len(list(br.forms())) > 1, 'no forms on this page'
# br.select_form(name="order") 选择特定的form
br.select_form(nr=0)
br.form['username'] = YOUR_LOGIN
br.form['password'] = YOUR_PASSWD
rsp = br.submit()
# login page, with error
print '\n***',rsp.geturl()
print 'Error due to invalid creds; resubmit w/valid creds'
assert rsp.geturl() == 'http://us.pycon.org/2011/account/login', rsp.geturl()
page = rsp.read()
err = str(BS(page).find("div",
{"id":"errorMsg"}).find('ul').find('li').string)
assert err == 'The username and/or password you specified are not correct.', err
br.select_form(nr=0)
br.form['username'] = YOUR_LOGIN
br.form['password'] = YOUR_PASSWD
示例9: Browser
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import form['username'] [as 别名]
#!/usr/bin/python
import re
from mechanize import Browser
br = Browser()
#install mechanise for running this script
#python 2.7
# Ignore robots.txt
br.set_handle_robots( False )
# Google demands a user-agent that isn't a robot
br.addheaders = [('User-agent', 'Firefox')]
# Retrieve the captive portal login page
br.open( "http://192.168.0.66:8090/" )
# Select the form and username password colum
# For other users change the form name and username ,password
# by looking into the source of login page{ for windows ctrl+u};
br.select_form( 'frmHTTPClientLogin' ) #form name
br.form[ 'username' ] = '' #Modify whats inside br.form[''] and enter the desired username in ''
br.form['password'] = '' #Modify whats inside br.form[''] and enter the desired password in ''
# login
br.submit()