本文整理汇总了Python中mechanize.Browser.click方法的典型用法代码示例。如果您正苦于以下问题:Python Browser.click方法的具体用法?Python Browser.click怎么用?Python Browser.click使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mechanize.Browser
的用法示例。
在下文中一共展示了Browser.click方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fetch
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import click [as 别名]
def fetch(url):
result_no = 0
browser = Browser(history = NoHistory())
browser.set_handle_robots(False)
browser.addheaders = USER_AGENT
page = browser.open(url)
html = page.read()
soup = bs(html)
browser.click()
print soup.prettify()
示例2: __init__
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import click [as 别名]
class LEAMsite:
def __init__(self, site, user, passwd):
self.site = site
self.error = False
self.b = Browser()
self.b.set_handle_robots(False)
try:
self.b.open(site)
except urllib2.URLError:
self.error = True
return
try:
# try and log in from the portlet
self.b.select_form('loginform')
except:
# try logging in from the main login page
self.b.open('/'.join((site,"login_form")))
self.b.select_form(nr=1)
self.b['__ac_name'] = user
self.b['__ac_password'] = passwd
r = self.b.open(self.b.click())
# plone changes have rendered this inoperable
# capture the response and look in the content
# body tag has class with login failure
def checkURL(self, url):
"""Tries to open a URL and return true if successful (object exists)
or false if error occurs.
"""
try:
rsp = self.b.open(url)
except:
return False
return True
def getURL(self, url, data=None, filename=None):
"""Simple interface for retrieving the contents of a URL
and writing it to a file or returning it as stringIO.
"""
#sys.stderr.write('getURL %s\n' % url)
rsp = self.b.open(url, data)
if filename:
f = file("./Inputs/"+filename, 'wb') # always write to Input folder
f.write(rsp.read())
f.close()
return None
else:
return StringIO(rsp.read())
def putFileURL(self, filename, url,
fileobj=None, title=None, type='text/plain'):
"""Simple interface for uploading a file to a plone site.
<URL> should be an existing folder on the site and
<filename> should be a readable file.
"""
#sys.stderr.write('putFileURL %s to %s\n' % (filename,url))
if not title: title = path.basename(filename)
if not fileobj: fileobj = open(filename, 'rb')
self.b.open('/'.join((url,'createObject?type_name=File')))
self.b.select_form("edit_form")
self.b['title'] = title
self.b.add_file(fileobj, type, path.basename(filename))
# form = self.b.find_control('file_delete')
# form.value = ["",]
self.b.submit("form.button.save")
# r = self.b.open(self.b.click())
# should check that it worked
def getFile(self, url, filename=None):
""" getFile -- gets a file using standard download from Plone site
url: The URL is pointer to the file on the Plone site
filename: optional filename where data will be written
"""
rsp = self.b.open(url_join(url,'at_download/file'))
if filename:
f = open(filename, 'wb')
f.write(rsp.read())
f.close()
return None
else:
return rsp.read()
def saveFile(self, url, dir=".", at_download=False):
"""Reads the response from a URL and saves it to a local
#.........这里部分代码省略.........
示例3: trilegal
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import click [as 别名]
#.........这里部分代码省略.........
myBrowser["eq_alpha"] = str(longitude)
myBrowser["eq_delta"] = str(latitude)
myBrowser["field"] = str(fieldArea)
myBrowser["icm_lim"] = str(passband)
myBrowser["mag_lim"] = str(magnitudeLimit)
myBrowser["mag_res"] = str(magnitudeResolution)
myBrowser["binary_kind"] = [str(int(includeBinaries))]
myBrowser["binary_frac"] = str(binaryFraction)
myBrowser["binary_mrinf"] = str(lowerBinaryMassRatio)
myBrowser["binary_mrsup"] = str(upperBinaryMassRatio)
myBrowser["extinction_kind"] = [str(extinctionType)]
if extinctionType == 1:
myBrowser["extinction_rho_sun"] = str(extinctionValue)
if extinctionType == 2:
myBrowser["extinction_infty"] = str(extinctionValue)
myBrowser["extinction_sigma"] = str(extinctionSigma)
if useThinDisc:
myBrowser["thindisk_kind"] = ["3"]
else:
myBrowser["thindisk_kind"] = ["0"]
if useThickDisc:
myBrowser["thickdisk_kind"] = ["3"]
else:
myBrowser["thickdisk_kind"] = ["0"]
if useBulge:
myBrowser["bulge_kind"] = ["2"]
else:
myBrowser["bulge_kind"] = ["0"]
# Submit the completed form
timestamp = strftime("%a, %d %b %Y %H:%M:%S", gmtime())
print("{0}: Submitting completed TRILEGAL web form".format(timestamp))
nextWebPage = myBrowser.submit()
# Trilegal is now computing the result. Click on the special "Refresh"
# button until the webpage says that the computations are finished.
timestamp = strftime("%a, %d %b %Y %H:%M:%S", gmtime())
print ("{0}: Waiting until TRILEGAL computations are finished".format(timestamp))
myBrowser.select_form(nr=0) # one form on the "be patient" web page
message = "Your job was finished"
while (message not in nextWebPage.read()):
nextWebPage = urlopen(myBrowser.click()) # click on the Refresh button
myBrowser.select_form(nr=0) # select form again, so that we can make a click again
sleep(5) # to not overload the website with refresh requests
# Get the url of the outputfile, and retrieve it. This can take a while.
timestamp = strftime("%a, %d %b %Y %H:%M:%S", gmtime())
print("{0}: Retrieving TRILEGAL output file".format(timestamp))
outputLink = myBrowser.links(url_regex="lgirardi/tmp/output").next()
urlretrieve(outputLink.absolute_url, outputFileName)
myBrowser.close()
# Save the parameters in an info file
parameterInfo = """
coordinateType {0}
longitude {1}
latitude {2}
fieldArea {3}
passband {4}
magnitudeLimit {5}
magnitudeResolution {6}
IMFtype {7}
includeBinaries {8}
binaryFraction {9}
lowerBinaryMassRatio {10}
upperBinaryMassRatio {11}
extinctionType {12}
extinctionValue {13}
extinctionSigma {14}
""".format(coordinateType,
longitude,
latitude,
fieldArea,
passband,
magnitudeLimit,
magnitudeResolution,
IMFtype,
includeBinaries,
binaryFraction,
lowerBinaryMassRatio,
upperBinaryMassRatio,
extinctionType,
extinctionValue,
extinctionSigma)
infoFileName = "info_" + outputFileName
with open(infoFileName, 'w') as infoFile:
infoFile.write(parameterInfo)
示例4: Browser
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import click [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']))
示例5: attack
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import click [as 别名]
def attack(address, htmlObject):
br = Browser()
br.open(address)
br.click(htmlObject)