To use splinter you need create a Browser instance:
from splinter import Browser
browser = Browser()Or, you can use it by a context manager, through the with statement:
from splinter import Browser
with Browser() as b:
# stuff using the browserThis last example will create a new browser window and close it when the cursor
reach the code outside the with statement, automatically.
splinter support three drivers: chrome, firefox and zopetestbrowser
browser = Browser('chrome')
browser = Browser('firefox')
browser = Browser('zope.testbrowser')You can use the visit method to navigate to other pages:
browser.visit('http://cobrateam.info')The visit method takes only a single parameter - the url to be visited.
You can visit a site protected with basic HTTP authentication by providing the username and password in the url.
browser.visit('http://username:password@cobrateam.info/protected')You can manage multiple windows (such as popups) through the windows object:
browser.windows # all open windows
browser.windows[0] # the first window
browser.windows[window_name] # the window_name window
browser.windows.current # the current window
browser.windows.current = browser.windows[3] # set current window to window 3
window = browser.windows[0]
window.is_current # boolean - whether window is current active window
window.is_current = True # set this window to be current window
window.next # the next window
window.prev # the previous window
window.close() # close this window
window.close_others() # close all windows except this oneThis window management interface is not compatible with the undocumented interface exposed in v0.6.0 and earlier.
You can reload a page using reload method:
browser.reload()You can back and forward on your browsing history using back and forward methods:
browser.visit('http://cobrateam.info')
browser.visit('https://splinter.readthedocs.io')
browser.back()
browser.forward()You can get the title of the visited page using the title attribute:
browser.titleYou can use the html attribute to get the html content of the visited page:
browser.htmlThe visited page's url can be accessed by the url attribute:
browser.urlYou can pass User-Agent on Browser instantiation.
b = Browser(user_agent="Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en)")