本文整理汇总了Python中mechanize.Browser.set_debug_http方法的典型用法代码示例。如果您正苦于以下问题:Python Browser.set_debug_http方法的具体用法?Python Browser.set_debug_http怎么用?Python Browser.set_debug_http使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mechanize.Browser
的用法示例。
在下文中一共展示了Browser.set_debug_http方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_mechanized_browser
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import set_debug_http [as 别名]
def get_mechanized_browser(self, url):
mech = Browser()
mech.set_handle_robots(False)
mech.set_debug_redirects(self.debug)
mech.set_debug_responses(self.debug)
mech.set_debug_http(self.debug)
mech.open(url)
assert mech.viewing_html()
return mech
示例2: create_browser
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import set_debug_http [as 别名]
def create_browser(debug=False):
browser = Browser(factory=mechanize.RobustFactory())
if debug:
# Maybe enable this if you want even more spam...
# logger = logging.getLogger("mechanize")
# logger.addHandler(logging.StreamHandler(sys.stdout))
# logger.setLevel(logging.DEBUG)
browser.set_debug_http(True)
browser.set_debug_responses(True)
browser.set_debug_redirects(True)
browser.set_handle_equiv(True)
browser.set_handle_gzip(True)
browser.set_handle_redirect(True)
browser.set_handle_referer(True)
browser.set_handle_robots(False)
browser.addheaders = HEADERS
return browser
示例3: set_debug_http
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import set_debug_http [as 别名]
def set_debug_http(self, *args, **kwargs):
B.set_debug_http(self, *args, **kwargs)
self._clone_actions['set_debug_http'] = ('set_debug_http',
args, kwargs)
示例4: Browser
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import set_debug_http [as 别名]
import re
from mechanize import Browser
br = Browser()
br.set_debug_http(True)
br.set_debug_responses(True)
br.set_debug_redirects(True)
I = 0
def save(func, *args, **kwargs):
global I
resp = func(*args, **kwargs)
page = resp.read()
filename = 'page%s.html' % I
I += 1
with open(filename, 'w') as f:
f.write(page)
return page
def login():
save(br.open, 'https://retail.santander.co.uk/LOGSUK_NS_ENS/BtoChannelDriver.ssobto?dse_operationName=LOGON')
br.select_form('formCustomerID_1')
br['infoLDAP_E.customerID'] = '7767598534'
challenge = save(br.submit)
br.select_form(nr=0)
if 'Place of Birth' in challenge:
answer = 'Stranraer'
else:
示例5: LconnectScraper
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import set_debug_http [as 别名]
class LconnectScraper(ClassDataScraper):
LCONNECT_URL = 'http://leopardweb.wit.edu/'
USERAGENT = 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.1) ' \
+ 'Gecko/20100122 firefox/3.6.1'
def __init__(self):
# Create a cookie jar and a browser
self._cookieJar = LWPCookieJar()
self._browser = Browser()
self._browser.set_cookiejar(self._cookieJar)
# Set Browser options
self._browser.set_handle_equiv(True)
self._browser.set_handle_gzip(True)
self._browser.set_handle_redirect(True)
self._browser.set_handle_referer(True)
self._browser.set_handle_robots(False)
self._browser.set_handle_refresh(_http.HTTPRefreshProcessor(),
max_time=1)
self._browser.addheaders = [('User-agent', LconnectScraper.USERAGENT)]
# Debugging
self._browser.set_debug_http(True)
self._browser.set_debug_redirects(True)
self._browser.set_debug_responses(True)
def getName(self):
return "Lconnect Scraper"
def connect(self):
"""
Attempts to connect to the data source
"""
try:
# Try to open a connection. 8 Second timeout
self._browser.open(LconnectScraper.LCONNECT_URL, timeout=8)
return True
except URLError:
return False
def disconnect(self):
"""
Disconnects from the data source
"""
self._browser.close()
def requiresAuthentication(self):
"""
Returns whether or not the scraper requires authentication information
"""
return True
def authenticate(self, username, password):
"""
Attempts to authenticate the scraper using username and password
"""
# If we're on the sign in page, try to sign in
if self._browser.title() == 'Sign In':
for form in self._browser.forms():
if form.name is None:
self._browser.form = list(self._browser.forms())[0]
self._browser['username'] = username
self._browser['password'] = password
self._browser.submit()
# If the browser's title is 'Main Menu',
# we've either successfully logged in, or we were already
if self._browser.title() == 'Main Menu':
return True
else:
return False
def getClassData(self):
"""
Returns a list of ClassData objects
"""
return []
示例6: __init__
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import set_debug_http [as 别名]
class FlickrBot:
# use favorite authors as contacts.
__url = "http://www.flickr.com"
__favorites_url = "http://www.flickr.com/photos/%s/favorites"
__favorite_regex = "/photos/[[email protected]]+/[0-9]+/"
__favorite_prefix = ""
__favorite_sufix = ""
__contact_regex = __favorite_regex
__complete_name_regex = __contact_regex
__complete_name_prefix = "/photos/"
__complete_name_sufix = "/"
__tag_regex = "/photos/tags/[a-zA-Z_0-9\-]+/"
__tag_prefix = "/photos/tags/"
__tag_sufix = "/"
__forb_tags = ["the", "and", "their", "at", "is", "in", "of", "a", "on", "for", "an", "with"]
def __init__(self, proxies_per_proto={}, debug=False):
self.__br = Browser()
self.__br.set_proxies(proxies_per_proto)
self.__br.set_debug_http(debug)
# no respect for robots.txt
self.__br.set_handle_robots(False)
self.__sleep_secs = 0
self.__sleep_module = 1
self.__gets = 0
# no sign in
# but i have a dummy user
# user: [email protected]
# password: zarasa123
pass
def set_sleep_secs(self, secs):
self.__sleep_secs = secs
def set_sleep_module(self, iterations):
self.__sleep_module = iterations
def __try_sleep(self):
self.__gets += 1
if self.__gets % self.__sleep_module == 0:
print "Sleeping for %f seconds, every %d GETs" % (self.__sleep_secs, self.__sleep_module)
time.sleep(self.__sleep_secs)
# most_viewed
# top_rated
# recently_featured
# watch_on_mobile
def seeds(self):
self.__try_sleep()
resp = self.__br.open("http://www.flickr.com/")
cont = resp.read()
matches = re.findall(self.__contact_regex, cont)
users = map(self.__strip_complete_name, matches)
return users
def search(self, query):
br = self.__br
# check if name exists.
try:
url = "http://www.flickr.com/photos/%s/favorites/" % query
print url
self.__try_sleep()
resp = self.__br.open(url)
cont = resp.read()
if not "favorites" in cont:
return []
except Exception, e:
if str(e) == "HTTP Error 404: Not Found":
return []
else:
raise e
return [cont]
示例7: __init__
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import set_debug_http [as 别名]
class YouTubeBot:
#__name_regex = 'href="http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendID=[0-9]+" linkindex='
# use favorite authors as contacts.
__contact_regex = 'http://www.youtube.com/profile\?user=[a-zA-Z_0-9]+'
__complete_name_regex = 'http://www.youtube.com/profile\?user=[a-zA-Z_0-9]+'
__complete_name_prefix = 'http://www.youtube.com/profile?user='
__complete_name_sufix = ''
__favorite_regex = 'http://www.youtube.com/watch\?v=[a-zA-Z_0-9\-]+'
__favorite_regex = 'http://www.youtube.com/watch\?v=[a-zA-Z_0-9\-]+'
__favorite_prefix = 'http://www.youtube.com/watch\?v='
__favorite_sufix = ''
__tag_regex = ' term=\'[a-zA-Z_0-9\-]+\'/>'
__tag_regex = ' term=\'[a-zA-Z_0-9\-]+\'/>'
__tag_prefix = ' term=\''
__tag_sufix = '\'/>'
__forb_tags = ['the', 'and', 'their', 'at', 'is', 'in', 'of',
'a', 'on', 'for', 'an', 'with', 'to']
def __init__(self, proxies_per_proto={}, debug=False):
self.__br = Browser()
self.__br.set_proxies(proxies_per_proto)
self.__br.set_debug_http(debug)
# no respect for robots.txt
self.__br.set_handle_robots(False)
self.__sleep_secs = 0.0
self.__sleep_module = 9999999
self.__sleep_failure = 120.0
self.__gets = 0
# no sign in
# but i have a dummy user
# user: [email protected]
# password: zarasa123
pass
def set_sleep_secs(self, secs):
self.__sleep_secs = float(secs)
def set_sleep_module(self, iterations):
self.__sleep_module = iterations
def set_sleep_failure(self, secs):
self.__sleep_failure = float(secs)
def __try_sleep(self):
self.__gets += 1
if self.__gets % self.__sleep_module == 0:
print 'Sleeping for %f seconds, every %d GETs' % (self.__sleep_secs, self.__sleep_module)
time.sleep(self.__sleep_secs)
#most_viewed
#top_rated
#recently_featured
#watch_on_mobile
def seeds(self, type='most_viewed'):
self.__try_sleep()
resp = self.__br.open('http://gdata.youtube.com/feeds/standardfeeds/' + type)
cont = resp.read()
matches = re.findall(self.__contact_regex, cont)
featured_users = map(self.__strip_complete_name, matches)
return featured_users
def search(self, query):
br = self.__br
# check if name exists.
try:
print 'http://gdata.youtube.com/feeds/users/%s/favorites' % query
self.__try_sleep()
resp = self.__br.open('http://gdata.youtube.com/feeds/users/%s/favorites' % query)
except Exception, e:
if str(e) == 'HTTP Error 404: Not Found':
return []
else:
raise e
return [resp.read()]
示例8: len
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import set_debug_http [as 别名]
if len(sys.argv) != 2: # require a URL to scan
sys.exit("Must specify a URL")
url = sys.argv[1]
print "Scanning: %s " % url
print
mech = Browser()
cj = LWPCookieJar()
mech.set_cookiejar(cj)
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.set_handle_robots(False)
mech.set_handle_equiv(True)
mech.set_handle_gzip(True)
mech.set_handle_referer(True)
mech.set_debug_http(True)
mech.set_debug_redirects(True)
mech.set_debug_responses(True)
page = mech.open(url)
html = page.read()
soup = BeautifulSoup(html)
# Extract all anchors on the page that include the string ".mp3"
anchors = soup.findAll(attrs={'href' : re.compile(".mp3")})
for a in anchors:
mp3link = a['href'] # Get the value of the href, not the whole tag/container!
# To get an output filename, split the URL on slashes and grab the last array item
urlfrags = mp3link.split('/')
save_as = urlfrags[len(urlfrags)-1] # Resolves to e.g. urlfrags[4]
print mp3link
示例9: __init__
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import set_debug_http [as 别名]
class TwitterBot:
__contact_regex = '<a href="http://twitter.com/[a-zA-Z_]+" rel="contact"><img alt=".*" class='
__complete_name_regex = 'alt=".*" class='
__complete_name_prefix = 'alt="'
__complete_name_sufix = '" class='
__url_regex = 'href=".*" rel'
__url_prefix = 'href="'
__url_sufix = '" rel'
def __init__(self, user='zarasa123', passw='zarasa123', proxies_per_proto={}, debug=False):
self.__br = Browser()
self.__br.set_proxies(proxies_per_proto)
self.__br.set_debug_http(debug)
# sign in
self.__br.open("http://twitter.com/")
forms = self.__br.forms()
form = forms.next()
self.__br.select_form(nr=0)
self.__br['username_or_email'] = user
self.__br['password'] = passw
resp = self.__br.submit()
def search(self, query):
br = self.__br
self.__br.select_form(name='user_search_form')
self.__br['q'] = query
resp = self.__br.submit()
links_urls = []
for link in br.links(url_regex="twitter.com/[a-zA-Z_]+"):
if not 'index.php' in link.url and \
not 'twitter.com/blog' in link.url and \
not 'twitter.com/home' in link.url:
links_urls.append(link.url)
br.back()
return links_urls
def __strip_complete_name(self, html_match):
match = re.search(self.__complete_name_regex, html_match)
match = match.group()[len(self.__complete_name_prefix):-len(self.__complete_name_sufix)]
return match
def __strip_url(self, html_match):
match = re.search(self.__url_regex, html_match)
match = match.group()[len(self.__url_prefix):-len(self.__url_sufix)]
return match
def contacts(self, name):
br = self.__br
# check if name exists.
results = self.search(name)
if len(results) == 0:
raise Exception('name "%s" doesn\'t exist in Twitter' % name)
# assume the first person that matches
name_link = results[0]
# retrieve the first n (20?) contacts as tuples (complete_name, twitter_url).
resp = self.__br.open(name_link + '/friends')
cont = resp.read()
matches = re.findall(self.__contact_regex, cont)
complete_names = map(self.__strip_complete_name, matches)
urls = map(self.__strip_url, matches)
return zip(complete_names, urls)
示例10: Mbank
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import set_debug_http [as 别名]
class Mbank(object):
"""
Glowna klasa realizujaca akcje logowania, przejscia na odpowiedni
formularz i wykonywania pozadanych akcji na stronach panelu klienta
mbanku.
"""
def __init__(self, id, password, bank_number=None):
self.id = id
self.password = password
self.bank_number = bank_number.replace(' ', '')
self.url = 'https://www.mbank.com.pl'
self.form_name = 'MainForm'
self.br = Browser()
# Ustawienie naglowkow (szczegolnie istotny Accept-Encoding)
# bez ktorego nie pobraloby dane w postaci CSV/HTML.
self.br.addheaders = [
('User-Agent', 'Mozilla/5.0 (X11; U; Linux x86_64; ' \
'pl-PL; rv:1.9.2.6) Gecko/20100628 Ubuntu/10.04 ' \
'(lucid) Firefox/3.6.6'),
('Accept-Encoding', 'gzip,deflate'),
('Referer', 'https://online.mbank.pl/pl/Login'),
]
# debugi
if DEBUG:
self.br.set_debug_redirects(True)
self.br.set_debug_responses(True)
self.br.set_debug_http(True)
def login(self):
"""
Metoda realizujaca logowanie sie do panelu klienta mbanku.
"""
now = datetime.datetime.now()
formated_now = now.strftime('%a, %d %b %Y, %X').lower()
self.br.open(self.url)
self.br.select_form(name=self.form_name)
self.br.form.set_all_readonly(False)
self.br.form.set_value(name='customer', value=self.id)
self.br.form.set_value(name='password', value=self.password)
self.br.form.set_value(name='localDT', value=formated_now)
return self.br.submit()
def select_account(self, bank_number):
"""
Wybiera konto bankowe na podstawie @bank_number i wysyla POST
z odpowiednimi parametrami dla danego konta.
"""
self.br.open('https://www.mbank.com.pl/accounts_list.aspx')
for l in self.br.links():
if l.text.replace(' ', '').find(bank_number) > -1:
break
# Znajdz atrybut onclick dla taga <a> z numerem konta bankowego.
for a in l.attrs:
if a[0] == 'onclick':
onclick = a[1].split("'")
break
# Wszystkie ponizsze dane pobierane sa z atrybutu onclick,
# w ktorym to uruchamiana jest funkcja JS doSubmit().
# Adres gdzie bedziemy slac dane.
addr = onclick[1]
# Metoda wysylania (POST)
method = onclick[5]
# Parametry
params = onclick[7]
self.br.select_form(name=self.form_name)
self.br.form.action = '%s%s' % (self.url, addr)
self.br.form.method = method
# Aktywuj inputa __PARAMETERS (ma ustawiony status readonly)
self.br.form.set_all_readonly(False)
# Przypisz parametry
self.br.form.set_value(name='__PARAMETERS', value=params)
return self.br.submit()
def history_form(self):
"""
Przejscie na formularz historii transakcji.
"""
self.br.select_form(name=self.form_name)
self.br.form.action = '%s%s' % (self.url, '/account_oper_list.aspx')
self.br.form.method = 'POST'
return self.br.submit()
def _get_history(self, type, last_day=False):
"""
Metoda ustawiajaca odpowiednie parametry na formularzu historii
transakcji i wysylajaca go.
"""
self.br.select_form(name=self.form_name)
# exportuj dane
self.br.form.find_control("export_oper_history_check").items[0].selected = True
# ustawienie selecta z typem danych (domyslnie HTML)
self.br.form.set_value(name='export_oper_history_format', value=[type])
#.........这里部分代码省略.........
示例11: PinboardAccount
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import set_debug_http [as 别名]
class PinboardAccount(object):
__allposts = 0
__postschanged = 0
# Time of last request so that the one second limit can be enforced.
__lastrequest = None
def __init__(self, username, password,refid):
self.br = Browser()
self.username=username
self.password = password
self.refid = refid
self.br.set_handle_robots(False)
# Browser options
self.br.set_handle_equiv(True)
self.br.set_handle_redirect(True)
self.br.set_handle_referer(True)
self.br.set_handle_robots(False)
self.br.set_debug_http(True)
self.br.set_debug_redirects(True)
self.br.set_debug_responses(True)
# Follows refresh 0 but not hangs on refresh > 0
self.br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
self.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')]
page = self.br.open(PINBOARD_URL)
form = self.br.forms().next() # the login form is unnamed...
if _debug:
print form.action # prints form
self.br.select_form(nr=0)
self.br["email"]=username
self.br["password"]=password
resp = self.br.submit()
con = resp.read()
matchExpr = "csrfmiddlewaretoken' value='(.*[^']?)'"
self.csrf=re.findall( matchExpr , con )[0]
print "CSRF is %s "%self.csrf
conn=self.br.open("http://pinterest.com/%s/"%refid).read()
@retry( Exception)
def createaPin(self, boardID , desc ,urlSite, taglist):
print "Post data is %s %s %s %s "%(boardID , desc , urlSite , taglist)
time.sleep(6)
self.br.open("http://pinterest.com/%s/pins/"%self.refid)
f=urllib.urlretrieve(urlSite)[0]
postData = {'board': boardID,
'details': desc ,
'link' : urlSite ,
'img_url' : urlSite ,
'tags' : taglist ,
'replies' : '' ,
'buyable' : '' ,
'img' : open( f , "rb") ,
'csrfmiddlewaretoken' : self.csrf}
request = self.br.open("http://pinterest.com/pin/create/", urllib.urlencode(postData))
content = json.loads(request.read()).get("url")
pinID = string.replace( content , "/pin/" , "" ).replace("/" , "")
return pinID
def getAllBoardsForUser(self , refName):
time.sleep(1)
resp = self.br.open("http://pinterest.com/%s/"%refName)
con = resp.read()
jsonBoard="""var myboards =(.*?[^]]?)]"""
m = re.findAll( re.compile(jsonBoard), con )
print m
content = json.loads(request.read()).get("url")
pinID = string.replace( content , "/pin/" , "" ).replace("/" , "")
return pinID
def doAllGood(self ,userName , password , comment, count , boardListStr):
os.system("/Users/Mark/apache-jmeter-2.6/bin/jmeter.sh -JuserName=%s -Jpassword=%s -Jnthreads=%s -JrefName=%s -JhostName=pinterest.com -JtargetBoardList=%s -n -t doAllGood.jmx " %(userName , password, count , self.refid, boardListStr ))
#os.system("\"D:\\java\\apache-jmeter-2.6\\bin\\jmeter.bat\" -JuserName=%s -Jpassword=%s -Jnthreads=%s -JrefName=%s -JhostName=pinterest.com -JtargetBoardList=%s -n -t doAllGood.jmx " %(userName , password, count , self.refid, boardListStr ))
def createBoard(self, csvFile):
boardList = self.getBoardListForUser()
print boardList
count = len([ x.strip() for x in file(csvFile).readlines() ])
print count
os.system("\"D:\\java\\apache-jmeter-2.6\\bin\\jmeter.bat\" -JuserName=%s -Jpassword=%s -Jnthreads=%s -JrefName=%s -JhostName=pinterest.com -n -t doCreateBoard.jmx " %(self.username , self.password, count ,self.refid ))
def getBoardListForUser(self ):
urlBoard = self.br.open("http://pinterest.com/%s"%self.refid)
#if re.compile(l.url).match("http://pinterest.com/%s/(.*?[^/]?)/"%self.refid)
self.listBoards = [ l.text for l in self.br.links() ]
return self.listBoards
示例12: Mbank
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import set_debug_http [as 别名]
class Mbank(object):
"""
Glowna klasa realizujaca akcje logowania, przejscia na odpowiedni
formularz i wykonywania pozadanych akcji na stronach panelu klienta
mbanku.
"""
def __init__(self, id, password, bank_number=None):
self.id = id
self.password = password
self.bank_number = bank_number.replace(" ", "")
self.url = "https://www.mbank.com.pl"
self.form_name = "MainForm"
self.br = Browser()
# Ustawienie naglowkow (szczegolnie istotny Accept-Encoding)
# bez ktorego nie pobraloby dane w postaci CSV/HTML.
self.br.addheaders = [
(
"User-Agent",
"Mozilla/5.0 (X11; U; Linux x86_64; "
"pl-PL; rv:1.9.2.6) Gecko/20100628 Ubuntu/10.04 "
"(lucid) Firefox/3.6.6",
),
("Accept-Encoding", "gzip,deflate"),
]
# debugi
if DEBUG:
self.br.set_debug_redirects(True)
self.br.set_debug_responses(True)
self.br.set_debug_http(True)
def login(self):
"""
Metoda realizujaca logowanie sie do panelu klienta mbanku.
"""
now = datetime.datetime.now()
formated_now = now.strftime("%a, %d %b %Y, %X").lower()
self.br.open(self.url)
self.br.select_form(name=self.form_name)
self.br.form.set_all_readonly(False)
self.br.form.set_value(name="customer", value=self.id)
self.br.form.set_value(name="password", value=self.password)
self.br.form.set_value(name="localDT", value=formated_now)
return self.br.submit()
def select_account(self, bank_number):
"""
Wybiera konto bankowe na podstawie @bank_number i wysyla POST
z odpowiednimi parametrami dla danego konta.
"""
self.br.open("https://www.mbank.com.pl/accounts_list.aspx")
for l in self.br.links():
if l.text.replace(" ", "").find(bank_number) > -1:
break
# Znajdz atrybut onclick dla taga <a> z numerem konta bankowego.
for a in l.attrs:
if a[0] == "onclick":
onclick = a[1].split("'")
break
# Wszystkie ponizsze dane pobierane sa z atrybutu onclick,
# w ktorym to uruchamiana jest funkcja JS doSubmit().
# Adres gdzie bedziemy slac dane.
addr = onclick[1]
# Metoda wysylania (POST)
method = onclick[5]
# Parametry
params = onclick[7]
self.br.select_form(name=self.form_name)
self.br.form.action = "%s%s" % (self.url, addr)
self.br.form.method = method
# Aktywuj inputa __PARAMETERS (ma ustawiony status readonly)
self.br.form.set_all_readonly(False)
# Przypisz parametry
self.br.form.set_value(name="__PARAMETERS", value=params)
return self.br.submit()
def history_form(self):
"""
Przejscie na formularz historii transakcji.
"""
self.br.select_form(name=self.form_name)
self.br.form.action = "%s%s" % (self.url, "/account_oper_list.aspx")
self.br.form.method = "POST"
return self.br.submit()
def _get_history(self, type, last_day=False):
"""
Metoda ustawiajaca odpowiednie parametry na formularzu historii
transakcji i wysylajaca go.
"""
self.br.select_form(name=self.form_name)
# exportuj dane
self.br.form.find_control("export_oper_history_check").items[0].selected = True
#.........这里部分代码省略.........
示例13: run_update
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import set_debug_http [as 别名]
def run_update():
global DEBUG, UPDATE_PROFILE, UPDATE_MOUCHE, UPDATE_EQUIPEMENT, UPDATE_VUE, UPDATE_APTITUDES, UPDATE_BONUS, UPDATE_GOWAPS
global VUE_LIST, GOWAPS_LIST
br = Browser()
br.set_debug_redirects(DEBUG)
br.set_debug_http(DEBUG)
if not DEBUG:
br.set_handle_robots( False )
br.set_handle_refresh( False )
br.open(login_url)
# gros hack tout laid car le formulaire n'a pas de nom
form_list = []
for f in br.forms():
form_list.append(f)
form_list[0].__dict__['name']='toto'
# fin du gros hack tout moche
br.select_form('toto')
br['login'] = username
br['password'] = password
br.submit()
for troll in trolls.keys():
printed = "MAJ de %s" % trolls[troll]['nom']
if UPDATE_PROFILE:
printed += " profil"
if not DEBUG:
br.open("%s%d" % (full_update_url, troll))
sleep(sleep_time)
if UPDATE_MOUCHE:
printed += " mouches"
if not DEBUG:
br.open("%s%d" % (mouche_update_url, troll))
sleep(sleep_time)
if UPDATE_EQUIPEMENT:
printed += " equipement"
if not DEBUG:
br.open("%s%d" % (equipement_update_url, troll))
sleep(sleep_time)
br.open("%s%d" % (GG_update_url, troll))
sleep(sleep_time)
if UPDATE_VUE and str(troll) in VUE_LIST:
printed += " vue"
if not DEBUG:
br.set_handle_redirect( False )
try:
br.open("%s%d" % (vue_update_url, troll))
except:
br.set_handle_redirect( True )
pass
sleep(sleep_time)
if UPDATE_GOWAPS and str(troll) in GOWAPS_LIST:
printed += " gowaps"
if not DEBUG:
br.open("%s%d" % (gowaps_update_url, troll))
sleep(sleep_time)
if UPDATE_APTITUDES:
printed += " competences"
if not DEBUG:
br.open("%s%d" % (aptitudes_update_url, troll))
sleep(sleep_time)
if UPDATE_BONUS:
printed += " bonus"
if not DEBUG:
br.open("%s%d" % (bonus_update_url, troll))
sleep(sleep_time)
print printed