本文整理汇总了Python中mechanize.Browser.submit方法的典型用法代码示例。如果您正苦于以下问题:Python Browser.submit方法的具体用法?Python Browser.submit怎么用?Python Browser.submit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mechanize.Browser
的用法示例。
在下文中一共展示了Browser.submit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Guarani
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import submit [as 别名]
class Guarani(object):
def __init__(self, user, passwd):
self.br = Browser()
self.user = user
self.passwd = passwd
self._login()
def _login(self):
self.br.open("https://guarani.exa.unicen.edu.ar/Guarani3w/")
self.br.open("https://guarani.exa.unicen.edu.ar/Guarani3w/includes/barra.inc.php")
self.br.follow_link(text_regex="Iniciar")
self.br.select_form(nr=0)
self.br["fUsuario"] = self.user
self.br["fClave"] = self.passwd
self.br.submit()
def _parseNotas(self, html):
soup = BeautifulSoup(html)
s_notas = soup.findAll('tr', {'class' : 'normal'})
notas = []
for s_nota in s_notas:
materia, nota = [x.text for x in s_nota.findAll('td')[:2]]
if nota != '':
notas.append([materia, nota])
return notas
def getNotasFinales(self):
self.br.open("https://guarani.exa.unicen.edu.ar/Guarani3w/operaciones.php")
self.br.follow_link(url_regex="consultarActProvisoria")
return self._parseNotas(self.br.response().read())
示例2: __init__
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import submit [as 别名]
def __init__(self, api_key, api_secret, frob, userid, password, perms):
from mechanize import Browser
browser = Browser()
browser.set_handle_robots(False)
browser.set_handle_refresh(True, max_time=1)
browser.set_handle_redirect(True)
api_sig = ''.join((api_secret, 'api_key', api_key, 'frob', frob, 'perms', perms))
api_sig = md5(api_sig)
login_url = "http://flickr.com/services/auth/?api_key=%s&perms=%s&frob=%s&api_sig=%s" % (api_key, perms, frob, api_sig)
browser.open(login_url)
browser.select_form(name='login_form')
browser['login'] = userid
browser['passwd'] = password
browser.submit()
for form in browser.forms():
try:
if form['frob'] == frob:
browser.form = form
browser.submit()
break
except:
pass
else:
raise Exception('no form for authentication found') # lame :-/
示例3: exec_
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import submit [as 别名]
def exec_(config, edition, another_edition, script):
USERNAME = config['USERNAME']
PASSWORD = config['PASSWORD']
SCRIPT_ID = config[edition]['SCRIPT_ID']
LOGIN_URL = 'https://monkeyguts.com/login/'
EDIT_URL = 'https://monkeyguts.com/submit.php?id={0}'.format(SCRIPT_ID)
summary = make_summary()
another_edition = config[another_edition]
another_edition = 'https://monkeyguts.com/code.php?id={0}'.format(another_edition['SCRIPT_ID'])
summary = summary.getResult(edition, another_edition)
b = Browser()
# home page
b.open(LOGIN_URL)
b.select_form(name='login')
b['username'] = USERNAME
b['password'] = PASSWORD
b.submit()
# edit source
b.open(EDIT_URL)
b.select_form(nr=1)
b['descr'] = summary.encode('utf-8')
b['code'] = script.encode('utf-8')
b.submit()
示例4: exec_
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import submit [as 别名]
def exec_(config, edition, another_edition, script):
USERNAME = config['USERNAME']
PASSWORD = config['PASSWORD']
SCRIPT_ID = config[edition]['SCRIPT_ID']
LOGIN_URL = 'https://greasyfork.org/users/sign_in'
EDIT_URL = 'https://greasyfork.org/scripts/{0}/versions/new'.format(SCRIPT_ID)
summary = make_summary()
another_edition = config[another_edition]
another_edition = 'https://greasyfork.org/scripts/{0}-{1}'.format(another_edition['SCRIPT_ID'], another_edition['SCRIPT_NAME'])
summary = summary.getResult(edition, another_edition)
b = Browser()
# login
b.open(LOGIN_URL)
b.select_form(nr=3)
b['user[email]'] = USERNAME
b['user[password]'] = PASSWORD
b.submit()
# edit source
b.open(EDIT_URL)
b.select_form(nr=2)
b['script_version[additional_info]'] = summary.encode('utf-8')
b['script_version[code]'] = script.encode('utf-8')
b.submit(name='commit')
示例5: __init__
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import submit [as 别名]
class HorizonInterface:
def __init__(self, username, password, site):
self.username = username
self.password = password
self.site = site
self.browser = Browser()
self.browser.open(self.site)
self.browser.select_form(name="security")
self.browser["sec1"] = self.username
self.browser["sec2"] = self.password
self.browser.submit()
def getCheckedOutBooks(self):
response = self.browser.follow_link(text_regex=r"^Items Out$")
bs = BeautifulSoup(response.read())
tables = bs.findAll('table', {'class': 'tableBackgroundHighlight'})
books = {}
if(len(tables) <= 1):
return books
trs = tables[1].fetch('tr', recursive=False)
for i in xrange(1, len(trs)):
tds = trs[i].fetch('td', recursive=False)
title = tds[1].find('a', {'class': 'mediumBoldAnchor'}).contents[0]
author = tds[1].find('a', {'class': 'normalBlackFont1'}).contents[0]
dueDate = tds[3].find('a').contents[0]
if not dueDate in books:
books[dueDate] = []
books[dueDate].append({'title': title,'author': author,'dueDate': dueDate})
return books
示例6: test_chap_form
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import submit [as 别名]
def test_chap_form(self):
"""this is a unit test for the chapters dropdown to
check that it is populated with the correct amount of chapters this
can be done by comapring the number of chapters in the db book_for
the selected book and then, comaring it with the actual number of
chapters in the chapters' dropdown"""
error_msg = """
you have a different number of chapters
in your dropdown than in your database
"""
books_from_db = BookInfo.objects.values_list('chaps', flat = True)
browser = Browser()
url = 'http://parallel-text.herokuapp.com/parallel_display/'
browser.open(url)
browser.select_form(name = 'book_form')
browser.submit()
self.html = browser.response().read()
soup = BeautifulSoup(self.html)
chapters_select = soup.findAll('select', id = "id_chapter_dd")
num_of_chapters = re.findall(r'<option value="(.*?)"',
str(chapters_select), re.DOTALL)
int_chap_dd = len(num_of_chapters)
int_chap_db = int(books_from_db[0])
self.assertEqual(int_chap_db, int_chap_dd, error_msg)
示例7: _initiate_the_wiki
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import submit [as 别名]
def _initiate_the_wiki(
self):
"""
*initiate the github wiki - not available in API so fill in form on github pages*
**Return:**
- None
.. todo::
"""
self.log.info('starting the ``_initiate_the_wiki`` method')
username = self.username
projectName = self.projectName
# sign into github
br = Browser()
br.set_handle_robots(False)
br.open("https://github.com/login")
br.select_form(nr=1)
br.form['login'] = self.username
br.form['password'] = self.password
br.submit()
# open wiki page for repo and create first page
response = br.open(
"https://github.com/%(username)s/%(projectName)s/wiki/_new" % locals())
br.select_form("gollum-editor")
response = br.submit()
self.log.info('completed the ``_initiate_the_wiki`` method')
return None
示例8: test_comment_reply_with_wrong_record
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import submit [as 别名]
def test_comment_reply_with_wrong_record(self):
"""webcomment - replying to comment using mismatching recid"""
# Juliet should not be able to reply to the comment, even through a public record
br = Browser()
br.open(CFG_SITE_URL + '/youraccount/login')
br.select_form(nr=0)
br['p_un'] = 'juliet'
br['p_pw'] = 'j123uliet'
br.submit()
br.open("%s/%s/%i/comments/add?action=REPLY&comid=%s&ln=en" % \
(CFG_SITE_URL, CFG_SITE_RECORD, self.public_record, self.restr_comid_1))
response = br.response().read()
if not self.msg2 in response and \
"Authorization failure" in response:
pass
else:
self.fail("Oops, users should not be able to reply to comment using mismatching recid")
# Jekyll should also not be able to reply the comment using the wrong recid
br = Browser()
br.open(CFG_SITE_URL + '/youraccount/login')
br.select_form(nr=0)
br['p_un'] = 'jekyll'
br['p_pw'] = 'j123ekyll'
br.submit()
br.open("%s/%s/%i/comments/add?action=REPLY&comid=%s&ln=en" % \
(CFG_SITE_URL, CFG_SITE_RECORD, self.public_record, self.restr_comid_1))
response = br.response().read()
if not self.msg2 in response and \
"Authorization failure" in response:
pass
else:
self.fail("Oops, users should not be able to reply to comment using mismatching recid")
示例9: test_comment_access_attachment_with_wrong_record
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import submit [as 别名]
def test_comment_access_attachment_with_wrong_record(self):
"""webcomment - accessing attachments using mismatching recid"""
# Juliet should not be able to access these files, especially with wrong recid
br = Browser()
br.open(CFG_SITE_URL + '/youraccount/login')
br.select_form(nr=0)
br['p_un'] = 'juliet'
br['p_pw'] = 'j123uliet'
br.submit()
try:
br.open("%s/%s/%i/comments/attachments/get/%i/file2" % \
(CFG_SITE_URL, CFG_SITE_RECORD, self.public_record, self.restr_comid_1))
response = br.response().read()
except HTTPError:
pass
else:
self.fail("Oops, users should not be able to access comment attachment using mismatching recid")
# Jekyll should also not be able to access these files when using wrong recid
br = Browser()
br.open(CFG_SITE_URL + '/youraccount/login')
br.select_form(nr=0)
br['p_un'] = 'jekyll'
br['p_pw'] = 'j123ekyll'
br.submit()
try:
br.open("%s/%s/%i/comments/attachments/get/%i/file2" % \
(CFG_SITE_URL, CFG_SITE_RECORD, self.public_record, self.restr_comid_1))
response = br.response().read()
response = br.response().read()
except HTTPError:
pass
else:
self.fail("Oops, users should not be able to access comment attachment using mismatching recid")
示例10: test_external_groups_visibility_messagespage
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import submit [as 别名]
def test_external_groups_visibility_messagespage(self):
"""webgroup - external group visibility in messages page"""
browser = Browser()
browser.open(cfg['CFG_SITE_SECURE_URL'] + "/youraccount/login")
browser.select_form(nr=0)
browser['nickname'] = 'admin'
browser['password'] = ''
browser.submit()
expected_response = "You are logged in as admin"
login_response_body = browser.response().read()
try:
login_response_body.index(expected_response)
except ValueError:
self.fail("Expected to see %s, got %s." % \
(expected_response, login_response_body))
browser.open(cfg['CFG_SITE_SECURE_URL'] + "/yourgroups/search?query=groups&term=test")
expected_response = self.goodgroup
groups_body = browser.response().read()
try:
groups_body.index(expected_response)
except ValueError:
self.fail("Expected to see %s, got %s." % \
(expected_response, groups_body))
not_expected_response = self.badgroup
try:
groups_body.index(not_expected_response)
except ValueError:
pass
else:
self.fail("Not expected to see %s, got %s." % \
(not_expected_response, groups_body))
示例11: test_external_groups_visibility_messagespage
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import submit [as 别名]
def test_external_groups_visibility_messagespage(self):
"""webgroup - external group visibility in messages page"""
browser = Browser()
browser.open(CFG_SITE_SECURE_URL + "/youraccount/login")
browser.select_form(nr=0)
browser["p_un"] = "admin"
browser["p_pw"] = ""
browser.submit()
expected_response = "You are logged in as admin"
login_response_body = browser.response().read()
try:
login_response_body.index(expected_response)
except ValueError:
self.fail("Expected to see %s, got %s." % (expected_response, login_response_body))
browser.open(CFG_SITE_SECURE_URL + "/yourmessages/write")
browser.select_form(nr=0)
browser["search_pattern"] = "b"
browser.submit(name="search_group")
expected_response = self.goodgroup
groups_body = browser.response().read()
try:
groups_body.index(expected_response)
except ValueError:
self.fail("Expected to see %s, got %s." % (expected_response, groups_body))
not_expected_response = self.badgroup
try:
groups_body.index(not_expected_response)
except ValueError:
pass
else:
self.fail("Not expected to see %s, got %s." % (not_expected_response, groups_body))
示例12: create
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import submit [as 别名]
def create():
while 1:
try:
br = Browser()
br.set_handle_robots(False)
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')]
br.open('https://classic.netaddress.com/tpl/Subscribe/Step1?Locale=en&AdInfo=&Referer=http%3A%2F%2Fwww.netaddress.com%2F&T=1332304112864372')
br.select_form(name='Step1')
userid = randomname()
br.form['usrUserId'] = userid
pwd = randomname()
br.form['newPasswd'] = pwd
br.form['RPasswd'] = pwd
br.form['usrFirst'] = randomname()
br.form['usrLast'] = randomname()
br.form['usrTimeZone'] = ['Africa/Abidjan']
br.form['usrCn'] = ['AF']
br.submit()
print "Created " + userid + " with password " + pwd
filo = open(filex, 'a')
filo.write(userid + "@usa.net" + ":" + pwd + "\n")
filo.close()
except:
print "error"
示例13: login_and_authorize
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import submit [as 别名]
def login_and_authorize(argv=None):
if argv is None:
argv = sys.argv
authorize_url = argv[1]
config = json.loads(argv[2])
print "AUTHORIZING", authorize_url
br = Browser()
br.set_debug_redirects(True)
br.open(authorize_url)
print "FIRST PAGE", br.title(), br.geturl()
br.select_form(nr=2)
br["login_email"] = config[u"testing_user"]
br["login_password"] = config[u"testing_password"]
resp = br.submit()
print "RESULT PAGE TITLE", br.title()
print "RESULT URL", resp.geturl()
assert br.viewing_html(), "Looks like it busted."
try:
br.select_form(nr=2)
br.submit()
assert br.viewing_html(), "Looks like it busted."
assert "API Request Authorized" in br.title(), "Title Is Wrong (bad email/password?): %r at %r" % (br.title(), br.geturl())
except FormNotFoundError:
print "Looks like we're blessed."
return "OK"
示例14: backup_database
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import submit [as 别名]
def backup_database(url, username, password, database, destination):
if not url.endswith("/"):
url+="/"
br = Browser()
br.open(url)
br.select_form(name="login_form")
br["pma_username"] = username
br["pma_password"] = password
login_response = br.submit()
resp = br.follow_link(url_regex=re.compile("^main\.php.*"))
resp = br.follow_link(url_regex=re.compile("\./server_export\.php.*"))
br.select_form(name="dump")
# Select SQL export
br.find_control(name="what").get(id="radio_plugin_sql").selected = True
# Select database to export
br.find_control(name="db_select[]").get(name=database).selected = True
# Add SQL DROP statements to export
br.find_control(name="sql_drop").get(id="checkbox_sql_drop").selected = True
# Send as file
br.find_control(name="asfile").get("sendit").selected = True
# Compress file with bzip
br.find_control(name="compression").get(id="radio_compression_bzip").selected = True
ret = br.submit()
open(destination, 'w').write(ret.read())
示例15: test_external_groups_visibility_groupspage
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import submit [as 别名]
def test_external_groups_visibility_groupspage(self):
"""webgroup - external group visibility in groups page"""
browser = Browser()
browser.open(CFG_SITE_SECURE_URL + "/youraccount/login")
browser.select_form(nr=0)
browser['p_un'] = 'admin'
browser['p_pw'] = ''
browser.submit()
expected_response = "You are logged in as admin"
login_response_body = browser.response().read()
try:
login_response_body.index(expected_response)
except ValueError:
self.fail("Expected to see %s, got %s." % \
(expected_response, login_response_body))
browser.open(CFG_SITE_SECURE_URL + "/yourgroups/display")
expected_response = self.goodgroup
groups_body = browser.response().read()
try:
groups_body.index(expected_response)
except ValueError:
self.fail("Expected to see %s, got %s." % \
(expected_response, groups_body))
not_expected_response = self.badgroup
try:
groups_body.index(not_expected_response)
except ValueError:
pass
else:
self.fail("Not expected to see %s, got %s." % \
(not_expected_response, groups_body))