本文整理汇总了Python中mechanize.Browser.reload方法的典型用法代码示例。如果您正苦于以下问题:Python Browser.reload方法的具体用法?Python Browser.reload怎么用?Python Browser.reload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mechanize.Browser
的用法示例。
在下文中一共展示了Browser.reload方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testToG
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import reload [as 别名]
def testToG():
k = r"http://www.batoto.net/read/_/188265/tower-of-god"
testv, testc = map(int, siteDict[k].split())
br = Browser()
br.open((r"http://www.batoto.net/read/_/188265/"
"tower-of-god_v1_ch1_by_the-company"))
resp = br.reload()
html = resp.read()
soup = BeautifulSoup("".join(html))
title = str(soup.find("title")).split()[4:8]
if title != ["vol", str(testv), "ch", str(testc)]:
webbrowser.open((r"http://www.batoto.net/read/_/188265/"
"tower-of-god_v1_ch1_by_the-company"))
print "New Tower of God"
print ""
incDict[(r"http://www.batoto.net/read/"
"_/188265/tower-of-god")] = (int(title[1])-testv,
int(title[3])-testc)
else:
incDict[(r"http://www.batoto.net/read/"
"_/188265/tower-of-god")] = (0, 0)
示例2: testWebDip
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import reload [as 别名]
def testWebDip():
br = Browser()
br.open("http://webdiplomacy.net/logon.php")
br.select_form(nr=0)
br['loginuser'] = "USERNAMEHERE"
br['loginpass'] = "PASSWORDHERE"
br.submit()
br.open("http://webdiplomacy.net/index.php")
resp = br.reload()
html = resp.read()
soup = BeautifulSoup("".join(html))
notices = soup.find("div", {"class": "gamelistings-tabs"})
if notices is None:
return
elif notices.find("img", {"src": "images/icons/alert.png"}):
webbrowser.open(br.geturl())
print "It's your turn in WebDiplomacy"
print ""
elif notices.find("img", {"src": "images/icons/mail.png"}):
webbrowser.open(br.geturl())
print "You have mail in WebDiplomacy"
print ""
示例3: open
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import reload [as 别名]
print "OpenID form submitted"
br.select_form(name="openid-form-redirection")
resp = br.submit() # Submit the form
print "OpenID redirection submitted"
br.select_form(nr=0)
br['password'] = open('pw').readline().rstrip()
resp = br.submit() # Submit the form
print "OpenID provider form submitted"
resp = br.open('https://bitminter.com/members/transactions')
payset = set()
print "Latest paid BTC transactions (streaming):"
while True:
page = resp.read()
soup = BeautifulSoup(page)
# Find all the payments listed on the page
payments = map(lambda x: [x.find_next_sibling().text,
x.find_parent().find_next_siblings()[1].text,
x.find_parent().find_previous_sibling().text],
soup.find_all(text=re.compile("Payment")))
payments.reverse()
for i in payments:
if re.search('BTC', i[1]) and i[2] not in payset:
print "\t", i[2], i[0]+":", i[1]
payset.add(i[2])
time.sleep(120)
resp = br.reload()
示例4: Bot
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import reload [as 别名]
class Bot(Thread):
def __init__(self, usr, pwd, pid, sale_cost, notification_email=None, \
purchase_item=None, max_iterations=sys.maxint, timeout=30):
self.login = usr
self.password = pwd
self.product_id = pid
self.sale_cost = sale_cost
self.notification_email = notification_email
self.purchase_item = purchase_item
self.max_iterations = max_iterations
self.timeout = timeout
self.browser = Browser()
Thread.__init__(self)
print "Initializing eCost Bot with login name: %s." % (self.login)
def go(self, event):
self.event = event
self.start()
def run(self):
product_found = self._product_search(self.product_id, self.max_iterations, self.timeout)
if not product_found:
return
add_to_cart = self.browser.follow_link(url_regex=product_found.group(1))
print "Product has been found and added to your shopping cart."
try:
view_cart = self.browser.follow_link(url=cart_url)
except LinkNotFoundError:
pass
print "Navigating to checkout page..."
checkout = self.browser.open(checkout_url)
print "Attempting to login as: %s." % (self.login)
self._login()
if self.notification_email:
self._send_notification_email(self.notification_email)
if not self.purchase_item:
print "You have elected not to automatically purchase the item, \
you must manually log into your eCost account to complete the transaction."
return
print "Purchase steps redacted."
print "end"
def _send_notification_email(self, notification_email):
import smtplib
from email.mime.text import MIMEText
body = "This is a message from your eCostAutobuyer that an item has \
been added to the shopping cart of your account."
msg = MIMEText(body)
msg['Subject'] = "Notification: An item has been added to your eCost account"
msg['From'] = '[email protected]'
msg['To'] = notification_email
s = smtplib.SMTP('smtp.gmail.com:587')
s.starttls()
s.login('[email protected]', 'password')
s.sendmail('[email protected]', [notification_email], msg.as_string())
s.quit()
print "A notification has been sent to %s" % (notification_email)
def _product_search(self, product_id, max_iterations, timeout):
print "Starting our product search for: %s" % (product_id)
cart_regex = re.compile('<a.*%s.*\s+.*(\d{7,})\_.*.jpg' % (product_id))
self.browser.open(countdown_url)
iteration = 0
while not self.event.isSet():
source = self.browser.response().read()
found_item = cart_regex.search(str(source))
if iteration > max_iterations:
break
if not found_item:
time.sleep(timeout)
iteration += 1
self.browser.reload()
continue
self.event.set()
return found_item
return None
def _login(self):
self.browser.select_form(name='aspnetForm')
self.browser['ctl00$uxMainPlaceHolder$uxEmail'] = self.login
self.browser['ctl00$uxMainPlaceHolder$uxPassword'] = self.password
#.........这里部分代码省略.........
示例5: take_action
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import reload [as 别名]
def take_action(self, parsed_args):
config_dir = '~/.kaggle-cli'
config_dir = os.path.expanduser(config_dir)
if os.path.isdir(config_dir):
config = ConfigParser.ConfigParser(allow_no_value=True)
config.readfp(open(config_dir + '/config'))
if parsed_args.username:
username = parsed_args.username
else:
username = config.get('user', 'username')
if parsed_args.password:
password = parsed_args.password
else:
password = config.get('user', 'password')
if parsed_args.competition:
competition = parsed_args.competition
else:
competition = config.get('user', 'competition')
base = 'https://www.kaggle.com'
login_url = 'https://www.kaggle.com/account/login'
submit_url = '/'.join([base, 'c', competition, 'submissions', 'attach'])
entry = parsed_args.entry
message = parsed_args.message
browser = Browser()
browser.open(login_url)
browser.select_form(nr=0)
browser['UserName'] = username
browser['Password'] = password
browser.submit()
browser.open(submit_url)
browser.select_form(nr=0)
browser.form.add_file(open(entry), filename=entry)
if message:
browser['SubmissionDescription'] = message
browser.submit()
while True:
leaderboard = html.fromstring(browser.response().read())
score = leaderboard.cssselect(
'.submission-results strong')
if len(score) and score[0].text_content():
score = score[0].text_content()
break
sleep(30)
browser.reload()
self.app.stdout.write(score + '\n')
示例6: attributes
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import reload [as 别名]
assert br.viewing_html()
print br.title()
print br.geturl()
#print br.info() # headers
#print br.read() # body
#br.close() # (shown for clarity; in fact Browser does this for you)
br.select_form(name="vb_login_username=User Name")
# Browser passes through unknown attributes (including methods)
# to the selected HTMLForm (from ClientForm).
br["vb_login_username"] = ["sleven"] # (the method here is __setitem__)
response2 = br.submit() # submit current form
# print currently selected form (don't call .submit() on this, use br.submit())
print br.form
response3 = br.back() # back to cheese shop (same data as response1)
# the history mechanism returns cached response objects
# we can still use the response, even though we closed it:
response3.seek(0)
response3.read()
response4 = br.reload() # fetches from server
for form in br.forms():
print form
# .links() optionally accepts the keyword args of .follow_/.find_link()
for link in br.links(url_regex="python.org"):
print link
br.follow_link(link) # takes EITHER Link instance OR keyword args
br.back()