本文整理汇总了Python中mechanize.Browser.add_password方法的典型用法代码示例。如果您正苦于以下问题:Python Browser.add_password方法的具体用法?Python Browser.add_password怎么用?Python Browser.add_password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mechanize.Browser
的用法示例。
在下文中一共展示了Browser.add_password方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: newBrowser
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import add_password [as 别名]
def newBrowser(self):
# Create new browsers all the time because its data structures grow
# unboundedly (texas#135)
br = Browser()
br.add_password(self.hostname, self.username, self.password)
br.set_handle_robots(None)
return br
示例2: GetServerConfigFile
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import add_password [as 别名]
def GetServerConfigFile(url_aastra, return_file):
br = Browser()
br.add_password(url_aastra, "admin", "22222")
try:
br.retrieve(url_aastra + "/servercfg.html", return_file)
return True
except:
log.warn("Maybe isn't a aastra phone? Are you Sure?")
return False
示例3: RemoveLocalConfig
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import add_password [as 别名]
def RemoveLocalConfig(url_aastra):
br = Browser()
br.add_password(url_aastra, "admin", "22222")
br.open(url_aastra + "/reset.html")
br.select_form(nr=0)
resetOption=br.form.controls[3]
resetOption.readonly=False
br.form["resetOption"]="2"
response=br.submit()
print response.read()
示例4: FactoryReset
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import add_password [as 别名]
def FactoryReset(url_aastra):
br = Browser()
br.add_password(url_aastra, "admin", "22222")
br.open(url_aastra + "/reset.html")
br.select_form(nr=0)
c=br.form.controls[3]
c.readonly=False
br.form["resetOption"]="1"
response=br.submit()
print response.read()
示例5: add_password
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import add_password [as 别名]
def add_password(self, *args, **kwargs):
B.add_password(self, *args, **kwargs)
self._clone_actions['add_password'] = ('add_password', args, kwargs)
示例6: Browser
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import add_password [as 别名]
from bs4 import BeautifulSoup
from mechanize import Browser
import re
import mechanize
url = "http://127.0.0.1/webgoat/attack"
br = Browser()
br.set_handle_robots(False)
br.add_password(url, "guest", "guest")
br.open(url)
br.select_form(nr=0)
sub = br.click(type="submit", nr=0)
br.open(sub)
soup = BeautifulSoup(br.response().read(), 'lxml')
link = soup.a
all_links = link.find_all_next('a')
print "Welche SQL-Operation?\n"
i = 0
SQL_links = []
for link in all_links:
if re.search(r'menu=1200', str(link)):
i = i + 1
SQL_links.append(str(link['href']))
示例7: Browser
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import add_password [as 别名]
Username = username
Password = password
import re
import sys
print "Please enter a description for this bug:"
desc = sys.stdin.read()
print "Thank you; your bug is now being submitted."
from mechanize import Browser
br = Browser()
br.add_password("http://trac.newartisans.com/ledger/login",
Username, Password)
print "Logging in to the Trac ..."
br.open("http://trac.newartisans.com/ledger/login")
assert br.viewing_html()
# follow second link with element text matching regular expression
print "Opening the New Ticket page ..."
resp1 = br.open("http://trac.newartisans.com/ledger/newticket")
newticket = None
index = 0
for form in br.forms():
if index == 1:
newticket = form
break
示例8: OutlookWebScraper
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import add_password [as 别名]
class OutlookWebScraper():
def __init__(self, domain, username, password):
logger.debug(locals())
self.domain = domain
self.username, self.password = username, password
self.is_logged_in = False
self.base_href = None
self.browser = Browser() # home to the mechanize headless browser-like entity
self.folder_cache = {} # a dict for storing folder names and lists of messages
self.message_cache = {} # a dict for storing message IDs and content
def add_to_cache(self, folder_name=None, message_urls=None, msgid=None, payload=None):
if folder_name: # simple - stores the message IDs from a folder with the folder name as a key
self.folder_cache[folder_name] = message_urls
return self.folder_cache[folder_name]
if msgid: # even simpler - store the raw e-mail under the message id
self.message_cache[msgid] = payload
return self.message_cache[msgid]
def find_in_cache(self, folder_name=None, msgid=None):
if msgid: # quick key-in-d lookup
if msgid in self.message_cache:
return self.message_cache[msgid]
if folder_name:
if folder_name in self.folder_cache:
return self.folder_cache[folder_name]
else: # i.e. no message of that id or no folder of that name
return False
def remove_from_cache(self, folder_name=None, msgid=None):
if msgid:
cache = find_in_cache(msgid=msgid) # search for the message
if cache:
del self.message_cache[msgid] # remove it
if not folder_name: # if that's it..
return True
# if a folder name was provided, or no message found, though..
if folder_name:
cache = find_in_cache(folder_name=folder_name) # search for a folder
if cache:
del self.folder_cache[folder_name] # if found, kill it
for id in cache:
del self.message_cache[id] # and remove the messages
return True
else:
return False
else: # nothing was found
return False
def flush_cache(self):
self.folder_cache = {} # really simple
self.message_cache = {}
return True
def login(self):
logger.debug(locals())
destination = urlparse.urljoin(self.domain, 'exchange/')
self.browser.add_password(destination, self.username, self.password)
self.browser.open(destination) # it should just work with basic auth, but let's deal with form as well
self.browser.select_form('logonForm')
self.browser['username'] = self.username
self.browser['password'] = self.password
self.browser.submit()
if 'You could not be logged on to Outlook Web Access' in self.browser.response().read():
raise InvalidLogin
m = self.browser.links().next()
if not m.base_url:
raise RetrievalError, "Couldn't find <base href> on page after logging in."
self.base_href = m.base_url
self.is_logged_in = True
def inbox(self, refresh=None):
"""
Returns the message IDs for all messages in the
Inbox, regardless of whether they've already been read. setting refresh forces an update.
"""
logger.debug(locals())
if refresh: # refresh kwarg. if set, forces a fresh load of the folder
return self.get_folder('Inbox', refresh=True)
else:
return self.get_folder('Inbox')
def get_folder(self, folder_name, refresh=None):
"""
Returns the message IDs for all messages in the
folder with the given name, regardless of whether the messages have
already been read. The folder name is case insensitive. setting refresh forces an update. if not set, cached messages
will be returned if they exist.
"""
logger.debug(locals())
if not refresh: # look in the cache
message_urls = find_in_cache(folder_name=folder_name)
if message_urls:
return message_urls
# if not found or not used, proceed
if not self.is_logged_in:
self.login()
url = self.base_href + urllib.quote(folder_name) + '/?Cmd=contents'
self.browser.open(url)
#.........这里部分代码省略.........
示例9: Browser
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import add_password [as 别名]
import urllib
import time
from bs4 import *
import re
import mechanize
from mechanize import Browser
from socket import error as SocketError
mech = Browser()
mech.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')]
mech.add_password('https://www.nebraska.gov/', 'USERNAME', 'PASSWORD')
mech.set_handle_robots(False)
baseurl = "https://www.nebraska.gov/justice/name.cgi"
z = open('lawyer_name.txt', 'wb')
firstcounter = 0
while firstcounter < 5:
try:
mech.open(baseurl)
firstcounter = 5
print "Got nebraska.gov"
except mechanize.HTTPError, e:
print "Broke on first loop. I'll try to load the search form again."
firstcounter += 1
time.sleep(30)
print "Taking a 30-second nap."
except SocketError, e:
print "Broke on first loop w/ socket error. I'll try to load the search form again."