本文整理汇总了Python中mechanize.Browser.select_form方法的典型用法代码示例。如果您正苦于以下问题:Python Browser.select_form方法的具体用法?Python Browser.select_form怎么用?Python Browser.select_form使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mechanize.Browser
的用法示例。
在下文中一共展示了Browser.select_form方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login_and_authorize
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import select_form [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"
示例2: __init__
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import select_form [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 select_form [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 select_form [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 select_form [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: make_request
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import select_form [as 别名]
def make_request(letter, people):
browser = Browser()
browser.open("https://directory.andrew.cmu.edu/")
browser.select_form(nr=0)
browser.form['search[generic_search_terms]'] = letter
browser.submit()
with open("response.html", "w") as f:
f.write(browser.response().read())
f.close()
page = open("response.html", "r").read()
soup = BeautifulSoup(page)
table = soup.findAll('tr')
for row in table[1:]:
info = row.findAll('td')
data = {}
data["first"] = clean(info[0].contents[1].contents[0])
data["last"] = clean(info[1].contents[1].contents[0])
data["affiliation"] = clean(info[3].contents[0])
data["department"] = clean(info[4].contents[0])
andrew = info[2].contents[1].contents[0]
people[andrew] = data
示例7: test_left_lang_form
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import select_form [as 别名]
def test_left_lang_form(self):
"""this is a unit test for the available left side languages dropdown
to check that it is populated with the correct amount of languages
this can be done by selecting a book from the database and then
selecting its available language and store those in a list.
after that we compare it with the actual number of languages
we get from the dropdown which was populated from the database"""
error_msg = """
you have a different number of languages for the selected book
in your dropdown than in your database
"""
lang_choices = []
browser = Browser()
url = 'http://parallel-text.herokuapp.com/parallel_display/'
browser.open(url)
browser.select_form(name = 'book_form')
selected_book = str(browser.form['book_dd'][0])
browser.submit()
id_of_book = BookInfo.objects.filter(title = selected_book)
all_translations = BookTranslation.objects.filter(
book_id = int(id_of_book[0].id))
for tran in all_translations:
lang = tran.language_id
lang_name = lang.name
lang_choices.append(lang_name)
self.html = browser.response().read()
soup = BeautifulSoup(self.html)
lang_select = soup.findAll('select', id = "id_left_lang_dd")
num_of_langs = re.findall(r'<option value="(.*?)"',
str(lang_select), re.DOTALL)
self.assertEqual(len(num_of_langs), len(lang_choices), error_msg)
示例8: test_comment_reply_with_wrong_record
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import select_form [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 select_form [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: login_url
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import select_form [as 别名]
def login_url(
url,
login,
passwd,
form_nomber,
login_name,
paswd_name,
submit_nomber
):
br = Browser(); showMessage('Создаю интерфейс браузера')
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
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(url); showMessage('Загружаю сайт и произвожу вход')
br.select_form(nr = form_nomber)
br[login_name] = login
br[paswd_name] = passwd
res = br.submit(nr = submit_nomber)
content = res.read()
#определить число страниц
maxPage = int(max_page(content)); showMessage('Определяю количество страниц и перехожу на последнюю')
curPage = 84
while curPage < maxPage:
res = br.open('http://forum.rsload.net/cat-kryaki-seriyniki-varez/topic-4820-page-%d.html' % (maxPage))
curPage = maxPage
maxPage = int(max_page(content))
content = res.read()
#парсинг ключей
if get_all_keys(content):
webbrowser.open_new_tab('http://forum.rsload.net/cat-kryaki-seriyniki-varez/topic-4820-page-%d.html' % (maxPage)) # Вернет True и откроет вкладку
示例11: test_external_groups_visibility_messagespage
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import select_form [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: test_external_groups_visibility_messagespage
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import select_form [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))
示例13: sa_login
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import select_form [as 别名]
def sa_login(sa_userName, sa_password):
'''Login to spolecneaktivity.cz portal as sa_userName user.
Temporary(?) no check
- if online,
- if not logged as other user
- succesfully logged in
'''
url_login = 'http://www.spolecneaktivity.cz'
br = Browser()
br.set_handle_robots(False)
ok = False
try:
r = br.open(url_login)
rru = r.read().upper()
if "LOGIN" in rru and "HESLO" in rru: # not logged in yet
br.select_form(nr=0)
br["userName"] = sa_userName
br["password"] = sa_password
r = br.submit()
ok = True
except:
pass
if not ok:
print u"sa_parse.sa_login: Selhalo přihlášení do spolecneaktivity.cz"
return br
示例14: create
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import select_form [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"
示例15: login_to_kaggle
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import select_form [as 别名]
def login_to_kaggle(self):
""" Login to Kaggle website
Parameters:
-----------
None
Returns:
browser: Browser
a mechanizer Browser object to be used for further access to site
"""
if self.verbose:
print("Logging in to Kaggle..."),
br = Browser()
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
br.open(self.kag_login_url)
br.select_form(nr=0)
br['UserName'] = self.kag_username
br['Password'] = self.kag_password
br.submit(nr=0)
if br.title() == "Login | Kaggle":
raise KaggleError("Unable to login Kaggle with username %s (response title: %s)" % (self.kag_username,br.title()))
if self.verbose:
print("done!")
return br