本文整理匯總了Python中mechanize.Browser方法的典型用法代碼示例。如果您正苦於以下問題:Python mechanize.Browser方法的具體用法?Python mechanize.Browser怎麽用?Python mechanize.Browser使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mechanize
的用法示例。
在下文中一共展示了mechanize.Browser方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Key_Ops_HTTP
# 需要導入模塊: import mechanize [as 別名]
# 或者: from mechanize import Browser [as 別名]
def Key_Ops_HTTP():
br = mechanize.Browser()
br.set_handle_robots(False)
br.addheaders = [('user-agent', ' Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/20100423 Ubuntu/10.04 (lucid) Firefox/3.6.3'),
('accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')]
try:
br.open("http://127.0.0.1:8000/admin/login/?next=/admin/")
except Exception as e:
# print "[!]Critical, could not open page."
# print "\n %s" % (e)
pass
br.form = list(br.forms())[0]
br["username"] = "RansomBot"
br["password"] = "prettyflypassw0rd"
br.submit()
# If log in was succesful retrieve key and post ID
###---@---###
######################################---NOT IMPLEMENTED---######################################
示例2: get_browser
# 需要導入模塊: import mechanize [as 別名]
# 或者: from mechanize import Browser [as 別名]
def get_browser(self):
'''Returns a mechanize.Browser object configured with the framework's global options.'''
br = mechanize.Browser()
# set the user-agent header
br.addheaders = [('User-agent', self._global_options['user-agent'])]
# set debug options
if self._global_options['verbosity'] >= 2:
br.set_debug_http(True)
br.set_debug_redirects(True)
br.set_debug_responses(True)
# set proxy
if self._global_options['proxy']:
br.set_proxies({'http': self._global_options['proxy'], 'https': self._global_options['proxy']})
# additional settings
br.set_handle_robots(False)
# set timeout
socket.setdefaulttimeout(self._global_options['timeout'])
return br
示例3: wiglePrint
# 需要導入模塊: import mechanize [as 別名]
# 或者: from mechanize import Browser [as 別名]
def wiglePrint(username, password, netid):
browser = mechanize.Browser()
browser.open('https://wigle.net')
#構造請求數據
reqData = urllib.urlencode({'credential_0':username, 'credential_1':password})
#請求登錄
browser.open('https://wigle.net/gps/gps/main/login', reqData)
params = {}
params['netid'] = netid
reqParams = urllib.urlencode(params)
respURL = 'https://wigle.net/gps/gps/main/confirmquery/'
resp = browser.open(respURL, reqParams).read()
print str(resp)
mapLat = 'N/A'
mapLon = 'N/A'
rLat = re.findall(search_lat, resp)
if rLat:
mapLat = rLat[0].split('&')[0].split('=')[1]
rLon = re.findall(search_lon, resp)
if rLon:
mapLon = rLon[0].split
print '[-] Lat: ' + mapLat + ', Lon: ' + mapLon
#打印網絡信息
示例4: wiglePrint
# 需要導入模塊: import mechanize [as 別名]
# 或者: from mechanize import Browser [as 別名]
def wiglePrint(username, password, netid):
browser = mechanize.Browser()
browser.open('https://wigle.net')
#構造請求數據
reqData = urllib.urlencode({'credential_0':username, 'credential_1':password})
#請求登錄
browser.open('https://wigle.net/gps/gps/main/login', reqData)
params = {}
params['netid'] = netid
reqParams = urllib.urlencode(params)
respURL = 'https://wigle.net/gps/gps/main/confirmquery/'
resp = browser.open(respURL, reqParams).read()
print str(resp)
mapLat = 'N/A'
mapLon = 'N/A'
rLat = re.findall(search_lat, resp)
if rLat:
mapLat = rLat[0].split('&')[0].split('=')[1]
rLon = re.findall(search_lon, resp)
if rLon:
mapLon = rLon[0].split
print '[-] Lat: ' + mapLat + ', Lon: ' + mapLon
示例5: login
# 需要導入模塊: import mechanize [as 別名]
# 或者: from mechanize import Browser [as 別名]
def login(self,ids):
try:
global br
br = mechanize.Browser()
br.set_handle_equiv(True)
br.set_handle_gzip(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
br.addheaders = [('User-Agent','Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 Mobile Safari/537.36')]
br.open(self.u.format('/login'))
br.select_form(nr=0)
br.form['email']=ids.split('|')[0]
br.form['pass']=ids.split('|')[1]
sub=br.submit().read()
if 'logout.php' in str(res) or 'mbasic_logout_button' in str(res):
self.ganti(ids)
else:
print(f'[\033[91mFailed\033[0m] {ids}')
except: pass
示例6: _init_browser
# 需要導入模塊: import mechanize [as 別名]
# 或者: from mechanize import Browser [as 別名]
def _init_browser(self):
"""
Ovveride this method with the appropriate way to prepare a logged in
browser.
"""
self.browser = mechanize.Browser()
self.browser.set_handle_robots(False)
self.browser.open(self.server_url + "/youraccount/login")
self.browser.select_form(nr=0)
try:
self.browser['nickname'] = self.user
self.browser['password'] = self.password
except:
self.browser['p_un'] = self.user
self.browser['p_pw'] = self.password
# Set login_method to be writable
self.browser.form.find_control('login_method').readonly = False
self.browser['login_method'] = self.login_method
self.browser.submit()
示例7: HTTPcode
# 需要導入模塊: import mechanize [as 別名]
# 或者: from mechanize import Browser [as 別名]
def HTTPcode(self):
try:
if self.agent == True:
br = Browser()
UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0"
header = {"User-Agent" : UserAgent}
br.set_handle_robots(False)
br.addheaders = [("User-agent", "Fifefox")]
resp = br.open(self.target).code
else:
resp = u.urlopen(self.target).getcode()
return(resp)
except (u.HTTPError, u.URLError):
return(404)
示例8: redirect
# 需要導入模塊: import mechanize [as 別名]
# 或者: from mechanize import Browser [as 別名]
def redirect(self):
try:
if self.agent == True:
br = Browser()
UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0"
header = {"User-Agent" : UserAgent}
br.set_handle_robots(False)
br.addheaders = [("User-agent", "Fifefox")]
remote_url = br.open(self.target).geturl()
else:
remote_url = u.urlopen(self.target).geturl()
return(remote_url)
except Exception as e:
print(e)
示例9: Findsubmit
# 需要導入模塊: import mechanize [as 別名]
# 或者: from mechanize import Browser [as 別名]
def Findsubmit(link):
global reqlist
try:
br = mechanize.Browser() # initiating the browser
br._factory.is_html = True
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(str(link), timeout=15)
if br.forms():
params = list(br.forms())
for par in params:
for p in par.controls:
ps = str(p)
# print p.name
if 'TextControl' in ps:
param = str(p.name)
reqstr = par.action + par.method + param
if reqstr not in reqlist:
reqlist.append(reqstr)
testxss(par.action, par.method, param)
except Exception, e:
print e
pass
示例10: __init__
# 需要導入模塊: import mechanize [as 別名]
# 或者: from mechanize import Browser [as 別名]
def __init__(self):
#install browser
self.br = mechanize.Browser()
self.br.set_handle_equiv(True)
self.br.set_handle_gzip(True)
self.br.set_handle_redirect(True)
self.br.set_handle_referer(True)
self.br.set_handle_robots(False)
self.br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
self.br.addheaders =[('Connection','keep-alive'),
('Pragma','no-cache'),
('Cache-Control','no-cache'),
('Origin','http://sms.payuterus.biz'),
('Upgrade-Insecure-Requests','1'),
('Content-Type','application/x-www-form-urlencoded'),
('User-Agent','Opera/9.80 (Android; Opera Mini/8.0.1807/36.1609; U; en) Presto/2.12.423 Version/12.16'),
('Accept','text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3'),
('Referer','http://sms.payuterus.biz/alpha/'),
('Accept-Encoding','gzip, deflate'),
('Accept-Language','id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7'),
('Cookie','_ga=GA1.2.131924726.1560439960; PHPSESSID=jjrqqaakmfcgfgbtjt8tve5595; _gid=GA1.2.1969561921.1561024035; _gat=1')
]
self.u='http://sms.payuterus.biz/alpha/'
self.banner()
示例11: __init__
# 需要導入模塊: import mechanize [as 別名]
# 或者: from mechanize import Browser [as 別名]
def __init__(self):
self.br = mechanize.Browser()
self.br.set_handle_equiv(True)
self.br.set_handle_gzip(True)
self.br.set_handle_redirect(True)
self.br.set_handle_referer(True)
self.br.set_handle_robots(False)
self.br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
self.br.addheaders =[('Connection','keep-alive'),
('Pragma','no-cache'),
('Cache-Control','no-cache'),
('Origin','http://sms.payuterus.biz'),
('Upgrade-Insecure-Requests','1'),
('Content-Type','application/x-www-form-urlencoded'),
('User-Agent','Mozilla/5.0 (Linux; Android 7.1.2; Redmi 4X Build/N2G47H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.91 Mobile Safari/537.36'),
('Accept','text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3'),
('Referer','http://sms.payuterus.biz/alpha/'),
('Accept-Encoding','gzip, deflate'),
('Accept-Language','id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7'),
('Cookie','_ga=GA1.2.131924726.1560439960; PHPSESSID=jjrqqaakmfcgfgbtjt8tve5595; _gid=GA1.2.1969561921.1561024035; _gat=1')
]
self.u='http://sms.payuterus.biz/alpha/'
self.tkmain()
示例12: retDomains
# 需要導入模塊: import mechanize [as 別名]
# 或者: from mechanize import Browser [as 別名]
def retDomains(ip):
# find parked domains by ip from Hurricane Electric, can use other source
# may be duplicate with get_parked(data)
domains = []
try:
url = "http://bgp.he.net/ip/" + ip + "#_dns"
userAgent = [('User-agent','Mozilla/5.0 (X11; U; '+\
'Linux 2.4.2-2 i586; en-US; m18) Gecko/20010131 Netscape6/6.01')]
browser = mechanize.Browser()
browser.addheaders = userAgent
page = browser.open(url)
html = page.read()
link_finder = re.compile('href="(.*?)"')
links = link_finder.findall(html)
for i in range (0, len(links)):
if links[i].find('/dns/') == 0:
domains.append(links[i][5:])
return domains
except:
return domains
示例13: getBrowers
# 需要導入模塊: import mechanize [as 別名]
# 或者: from mechanize import Browser [as 別名]
def getBrowers():
br = mechanize.Browser(history=NoHistory())
#options
br.set_handle_equiv(True)
#br.set_handle_gzip(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)##關聯cookies
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
br.set_debug_http(False)
br.set_debug_redirects(False)
br.set_debug_responses(False)
br.addheaders = [("User-agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36")]
return br
示例14: cli
# 需要導入模塊: import mechanize [as 別名]
# 或者: from mechanize import Browser [as 別名]
def cli(scores, transfers):
browser = mechanize.Browser()
browser.set_handle_robots(False) #Allows everything to be written
cookies = mechanize.CookieJar()
browser.set_cookiejar(cookies)
browser.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.41 Safari/534.7')]
browser.set_handle_refresh(False) #Sometimes hangs without this
if(scores): #Called after score option is called
soup = find_soup(browser,'http://www.goal.com/en-in/live-scores') #Gets HTML of entire page
score_box = soup.find_all('div',attrs={'class':'match-main-data'}) #Navigating to where the score is available in the page
click.echo("\nThe scores of all matches being played currently is displayed below:")
click.echo("--------------------------------------------------------------------")
for i in score_box: #To get the score of all live matches and recently done matches
print i.text
click.echo("--------------------------------------------------------------------")
click.echo("\n\nNOTE: ALL THE MATCH TIMINGS ARE IN GMT\n\n")
if(transfers):
soup = find_soup(browser,'http://www.goal.com/en-us/transfer-rumours/1') #Gets HTML of entire page
rumours = soup.select(".transfer-card__desc p")
click.echo("\nThe latest Transfer news & rumours are displayed below:")
click.echo("--------------------------------------------------------------------")
for i in rumours:
print("->"+i.text)
click.echo("--------------------------------------------------------------------")
示例15: cli
# 需要導入模塊: import mechanize [as 別名]
# 或者: from mechanize import Browser [as 別名]
def cli(google,wiki):
browser = mechanize.Browser()
browser.set_handle_robots(False) #Allows everything to be written
cookies = mechanize.CookieJar()
browser.set_cookiejar(cookies)
browser.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.41 Safari/534.7')]
browser.set_handle_refresh(False) #Sometimes hangs without this
if(google):
query = raw_input("Enter the topic you want to search about: ")
for link in search(query, tld="co.in", num=10, stop=1, pause=2):
print link
if(wiki):
wiki_topic = raw_input('Enter the topic you want to read about: ')
result = wikipedia.page(title=wiki_topic,auto_suggest=True,redirect=True, preload=False)
wiki_content = result.content
print wiki_content