本文整理汇总了Python中splinter.Browser.check方法的典型用法代码示例。如果您正苦于以下问题:Python Browser.check方法的具体用法?Python Browser.check怎么用?Python Browser.check使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类splinter.Browser
的用法示例。
在下文中一共展示了Browser.check方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: xfinity
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import check [as 别名]
def xfinity(browser=None):
if not browser:
print ("Making browser...")
browser = Browser('phantomjs')
print ("Trying google.com...")
browser.visit('http://google.com/')
if 'google.' in browser.url:
print ("google.com connected :)")
return
print ("Sign up...")
browser.click_link_by_partial_text('Sign up')
print ("Filling form...")
browser.select("rateplanid", "spn")
browser.check('spn_terms')
browser.fill('spn_postal', '12345')
browser.fill('spn_email', '[email protected]')
print ("Submitting...")
sleep(3) # it did not work without the sleeps
browser.find_by_css('.startSessionButton').type(' \n')
sleep(7)
browser.ensure_success_response()
print (browser.screenshot())
示例2: InstagramWebBot
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import check [as 别名]
class InstagramWebBot(object):
'''Instagram Web Bot for automatic things using web browser.'''
LOGIN_URL = 'http://instagram.com/accounts/login/';
MANAGE_CLIENTS_URL = 'http://instagram.com/developer/clients/manage/'
REGISTER_CLIENT_URL = 'http://instagram.com/developer/clients/register/'
REGISTER_DEVELOPER_URL = 'http://instagram.com/developer/register/'
LOGOUT_URL = 'http://instagram.com/accounts/logout/'
CHANGE_PASSWORD_URL = 'http://instagram.com/accounts/password/change/'
APP_REDIRECT_URI = 'http://lovematically.com/complete/instagram'
APP_NAME_CHOICES = ['LOVE', 'AMOR', 'AMORE', 'AMOUR']
WAIT_TIME = 5
is_logged_in = False
is_developer = False
def __init__(self, username, password, browser=None):
if browser is not None:
self.browser = browser
self.browser.visit(self.LOGOUT_URL)
else:
self.browser = Browser('firefox', user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36")
self.username = username
self.password = password
def slugify(self, str):
return re.sub(r'\W+','_',str).lower()
def login(self):
'''Creates a login session'''
self.browser.visit(self.LOGIN_URL)
self.browser.fill('username', self.username)
self.browser.fill('password', self.password)
btn = self.browser.find_by_value('Log in').first
btn.click()
if self.browser.title == 'Instagram':
self.is_logged_in = True
logger.info('Logged in as %s' % self.username)
else:
self.is_logged_in = False
logger.error('Login Failed for %s' % self.username)
def change_password(self):
self.browser.visit(self.CHANGE_PASSWORD_URL)
new_password = random_string_generator(8)
self.browser.fill('old_password', self.password)
self.browser.fill('new_password1', new_password)
self.browser.fill('new_password2', new_password)
btn = self.browser.find_by_value('Change Password').first
btn.click()
if self.browser.is_text_present('Thanks! You have successfully changed your password.'):
logger.info('Password Changed')
logger.info(new_password)
return new_password
else:
return None
def register_developer(self, website="", phone_number="", description=""):
'''
Registers the user for developer access in instagram
'''
result = {}
if not self.is_logged_in:
logger.error('Must be logged-in to create register as a developer.')
return result;
self.browser.visit(self.MANAGE_CLIENTS_URL)
if self.browser.is_text_present('Developer Signup'):
logger.info('Registering as developer')
self.browser.fill('website', website)
self.browser.fill('phone_number', phone_number)
self.browser.fill('description', description)
self.browser.check('accept_terms')
btn = self.browser.find_by_value('Sign up').first
btn.click()
self.register_developer(website, phone_number, description)
elif self.browser.is_text_present('Register a New Client'):
logger.info('Developer registration done')
self.is_developer = True
else:
logger.info('Developer registration failed')
self.is_developer = False
return result
def create_api_client(self, app_name, description, website_url, redirect_uri):
'''Creates a new api client.
TODO:
1. Add more error handling cases.
'''
result = {}
if not self.is_logged_in:
logger.error('Must be logged-in to create a api client.')
return result;
#.........这里部分代码省略.........
示例3: __init__
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import check [as 别名]
class Session:
def __init__(self, browser, user):
self.browser = Browser(browser)
self.browser.visit('http://jizdenky.studentagency.cz/')
self.browser.fill_form({'passwordAccountCode': user['login'],
'password': user['password']})
self.browser.execute_script('window.scrollTo(0, 100)')
button = self.browser.find_by_value('Přihlásit').first
button.click()
self.user = user
self.log = logging.getLogger(__name__)
def go_search(self):
self.browser.visit('http://jizdenky.studentagency.cz/')
def search(self, task, date_return=None, is_open=False):
self.browser.find_by_id('hp_form_itinerar').first \
.find_by_xpath('div/input[@type="radio"]'
)[1 if date_return or is_open else 0].check()
for city, i in [(task.from_city, 1), (task.to_city, 2)]:
self.browser.find_by_css('input[tabindex="{}"]'.format(i)) \
.first.fill(city)
for item in self.browser.find_by_css('.ui-menu-item'):
link = item.find_by_tag('a')
if link.value.lower() == city.lower():
link.click()
break
self.browser.fill('departure:dateField', task.date)
if date_return:
self.browser.fill('returnDeparture:dateField', date_return)
if is_open:
self.browser.check('returnTicketOpen')
self.browser.find_option_by_text('ISIC').first.check()
self.browser.find_by_value('Vyhledat').first.click()
while self.browser.is_element_not_present_by_css('.left_column',
wait_time=1):
pass
items = self.browser.find_by_css('.left_column') \
.find_by_xpath('div/div/*')
connections = []
for item in items:
if item.tag_name == 'h2':
date_local = item.text.split(' ')[1]
elif item.tag_name == 'div' and item.has_class('routeSummary'):
assert date_local
if date_local != task.date:
break
connections.append(Connection(item))
return connections
def order_time(self, connection):
while True:
if connection.click():
self.browser
dialog = self.browser.find_by_css('[id^=_wicket_window]')
if dialog:
dialog.first.find_by_tag('button').click()
if self.browser.is_element_present_by_id('sumary_lines',
wait_time=1):
break
self.browser.find_by_id('sumary_lines') \
.first.find_by_tag('button') \
.first.click()
seats = {}
bus = self.browser.find_by_css('.seatsContainer')
if bus:
for seat in bus.first.find_by_css(
'.seatContainer:not([style*=blocked])'):
seats[int(seat.find_by_tag('div').first.html[:-1])] = seat
else:
bus = self.browser.find_by_css('.vehicle')
for seat in bus.first.find_by_css('.free, .selected'):
seats[int(seat.text[:-1])] = seat
return seats
def order_seat(self, seat):
if not seat.has_class('selected'):
seat.click()
for fs in self.browser.find_by_css('fieldset.topRoute'):
legend = fs.find_by_css('legend')
if legend and 'Pojištění' in legend[0].text:
for package in fs.find_by_css('.insurancePackageType'):
if 'nechci' in package.find_by_tag('label').text:
package.find_by_tag('input').click()
time.sleep(1)
submit = self.browser.find_by_css('[name^=buttonContainer]').first
interaction_type = submit.text
reserved = 'Rezervovat' in interaction_type
if not reserved:
submit.click()
time.sleep(1)
data = (self.user['first'],
self.user['last'],
self.user['email'],
self.user['phone'])
for item, value in zip(self.browser.find_by_id('passengerInfo')
.first.find_by_tag('input'),
data):
item.fill(value)
#.........这里部分代码省略.........
示例4: register_mac_with_xfinity
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import check [as 别名]
def register_mac_with_xfinity(mac,output, count = 0,time_out = 30):
if(count >= 2):
return False
if count > 0:
output.append("Uncertain if successful, trying again")
b = Browser('phantomjs') #'phantomjs' #webdriver.PhantomJS()
output.append("Browser Launched")
success = False
try:
url = "https://xfinity.nnu.com/xfinitywifi/?client-mac="+mac.lower()
socket.setdefaulttimeout(60)
b.visit(url)
if b.is_text_present("Your complimentary session has expired."):
# b.quit()
output.append("Mac has already been registered")
success = True
if(success==False):
b.select("rateplanid","spn")
# print b.url
email = str(random.randrange(10000000,99999999))+'@comcast.com'
zip_code = random.randrange(10000,99999)
try:
b.fill('spn_postal', zip_code)
b.fill('spn_email', email)
except:
pass
try:
b.check('spn_terms')
except:
pass
url = b.url
b.find_by_value('submit').first.click()
b.find_by_value('submit').first.click()
output.append("Submitting Mac Request, Waiting for result")
waitTime = 0
while(b.url == url and waitTime < time_out): #total shit...
time.sleep(1)
waitTime += 1
if waitTime>0 and waitTime%15 == 0:
output.append("Waiting for request to complete ... ["+str(waitTime)+"s]")
#TODO validate..... ie did webpage load/etc
if(b.is_text_present("Your complimentary session is now active!")):
success = True
if(waitTime >= time_out and not success):
success = register_mac_with_xfinity(mac,output,count=count+1, time_out=time_out)
except Exception, err:
print err.message
print b.url
print b.html
success = register_mac_with_xfinity(mac, output, count=count+1, time_out=time_out)
pass