Skip to content

Quickstart

Manuel Cabral edited this page Jul 13, 2023 · 9 revisions

Install

PyPI package is not available yet

Clone the repository

git clone https://github.com/manucabral/pybrinf.git

Get started

First step, you need to initialize the package.

from pybrinf import Brinf

brinf = Brinf()
brinf.init()

Now, you can choose to use a installed browser or your default browser.

# use default browser
browser = brinf.default_browser

# use another installed browser
browser = brinf.browser('edge')

if you want to know what browsers are supported, click here or use the following code.

print(brinf.supported_browsers)

Important

if you have changed the local path of the browser you need to set it.

# setting local path
browser.set_local_path('C:\Users\yeah\...')

# setting executable path
browser.set_app_path('C:\Users\yeah\...')

History and Downloads

Let's get all downloads from all installed browsers.

Important! Apply limit if you don't want performance issues.

downloads = brinf.downloads()
for download in downloads:
    print(download.url, download.browser)

You can apply a limit and offset or exclude browsers

# apply limit, offset and exclude chrome and edge browsers
downloads = brinf.downloads(limit=10, offset=5, exclude=['chrome', 'edge'])

# exclude only chrome browser
downloads = brinf.downloads(exclude='chrome')

Same applies on get all History.

history = brinf.history()
for item in history:
    print(item.url, item.last_visit, item.browser)

Browser Session

Let's get last Session from a chromium browser, for now Firefox is not supported.

Important! if you do not have privileges when executing your script, you will get an access denied error.

Solve it running your python script as an administrator or closing the browser using the close() method.

default_browser = brinf.default_browser
if default_browser.running:
    default_browser.close()
session = defalt_browser.session()

Now you can get last updated Tabs.

for tab in session.tabs():
    print(tab.url, tab.active, tab.pinned)

Also get the current tab

tab = session.current_tab
print(tab.url, tab.title)

Dev tools

Let's enable dev tools mode for a chromium browser.

With dev tools enable you can get the current tabs without using a browser session. Keep in mind that it is still in development.

browser = brinf.default_browser

# if the browser is running close it!
if browser.running:
    browser.close() 

# let's enable dev tools
browser.dev_tools = True # or browser.dev_tools(True)

# opens the browser with dev tools enable
browser.open()

Let's get all current tabs

tabs = browser.tabs()

for tab in tabs:
    print(tab.url)

active_tab = tabs[0]

NOTE: the first element is the current active tab.

Clone this wiki locally