A Python library for automating BrowserAutomationStudio (BAS) using headless Chromium browsers and Windows GUI program.
Project description
py-bas-automation
Note: This project originally started as a working proof of concept
and does not aim to offer extensive support or
documentation. It serves as a fundamental demonstration of the concept and should be considered a foundation for further
development or experimentation.
Description
This library enables you to work with BAS (BrowserAutomationStudio) using headless Chromium browsers and a customizable Windows GUI program, while controlling it with Python ❤️.
Features
- Run BAS with headless browsers and a user-friendly, customizable Windows GUI program (BrowserAutomationStudio).
- It includes a unique feature that provides a
fingerprint
for each browser instance using FingerprintSwitcher. Please note, this is a paid feature. - Utilize Playwright to control BAS.
How it works
When BAS starts, it executes cmd_initial.py, which creates tasks and saves them to disk. Subsequently, BAS obtains data, configures, and initiates a browser instances with the provided tasks.
Afterward, BAS runs cmd_worker.py with the task_id
and the remote-debugging-port
number as
command-line parameters.
cmd_worker.py retrieves both the ws_endpoint
and remote-debugging-port
from the command line and
handles complex tasks using Playwright. For example, it can open a page, fill out a
forms, make screenshot, etc.
Requirements
- Windows 10/11, Windows Server 2022(tested on 21H2).
- Python 3.11+ (https://www.python.org/downloads/).
- Poetry (https://python-poetry.org/docs/#installation).
- Git (https://git-scm.com/downloads).
- Make (https://chocolatey.org/packages/make) - optional.
- A license for FingerprintSwitcher. This is a paid feature.
Installation
- Checkout the latest version of
py-bas-automation
to the current project with Poetry:
git clone git@github.com:sergerdn/py-bas-automation.git
cd py-bas-automation
poetry install
- Download the latest compiled BAS program from Releases.
Running
- Run the downloaded BAS program and set variables in the BAS GUI.
- Click "OK" button to start program.
Advanced Usage
Here's a basic example of using py-bas-automation
:
- Initial script to create tasks:
import json
from pybas_automation.task import BasTask, TaskStorage, TaskStorageModeEnum
from pybas_automation.browser_profile import BrowserProfileStorage
fingerprint_key = "your_fingerprint_key"
# Create a new task
task = BasTask()
# Save the task to storage, default location is
# C:\Users\{username}\AppData\Local\PyBASTasks
task_storage = TaskStorage(mode=TaskStorageModeEnum.READ_WRITE)
task_storage.save(task)
# Initialize a browser profile storage, default location is
# C:\Users\{username}\AppData\Local\PyBASProfiles
browser_profile_storage = BrowserProfileStorage(fingerprint_key=fingerprint_key)
# Create 20 fresh profiles on disk
for _ in range(0, 20):
browser_profile = browser_profile_storage.new()
# Add created browser profiles to tasks
for browser_profile in browser_profile_storage.load_all():
task = BasTask()
task.browser_settings.profile.profile_folder_path = browser_profile.profile_dir
task_storage.save(task=task)
task_file_path = task_storage.task_file_path
# print path to tasks file for use it in BAS
print(json.dumps({"tasks_file": str(task_file_path)}, indent=4))
- Worker script to retrieve the ws_endpoint from bas and handle the complex tasks:
from uuid import UUID
from playwright.sync_api import sync_playwright
from pybas_automation.task import BasTask, TaskStorage, TaskStorageModeEnum
from pybas_automation.browser_remote import BrowserRemote
# skip code to getting ws_endpoint from cmd line ...
task_id = UUID("some_task_id_that_we_getting_from_cmd_line_from_BAS")
# Create a new task storage
task_storage = TaskStorage(mode=TaskStorageModeEnum.READ)
found_task = task_storage.get(task_id=task_id)
# Do something with task if needed...
# Save the task to storage, default location is
# Skip code to getting remote_debugging_port from cmd line ...
remote_debugging_port = 9222
remote_browser = BrowserRemote(remote_debugging_port=remote_debugging_port)
# Get ws_endpoint from remote_debugging_port
remote_browser.find_ws()
ws_endpoint = remote_browser.ws_endpoint
with sync_playwright() as pw:
# Connect to an existing browser instance
browser = pw.chromium.connect_over_cdp(ws_endpoint)
# Get the existing pages in the connected browser instance
page = browser.contexts[0].pages[0]
# Doing some work with page
page.goto("https://playwright.dev/python/")
Contributing
Your ideas and contributions are highly valued. Please do not hesitate to open an issue if you have suggestions, questions, or if you would like to contribute to its enhancement.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pybas_automation-0.1.0.tar.gz
.
File metadata
- Download URL: pybas_automation-0.1.0.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.6 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 770320de14b516d5930e2b8041276253b330c13c6a32f587be57efab9beb7e49 |
|
MD5 | 40045eb7f66c6473c20ad5114ff7dd61 |
|
BLAKE2b-256 | 93de6ea914da84d0f4dd6ef27b4de47bf344ca6af7ca3a7ca1efb480de60cbed |
File details
Details for the file pybas_automation-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: pybas_automation-0.1.0-py3-none-any.whl
- Upload date:
- Size: 22.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.6 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c19134593ba4474136ff247db5bb03030bf201aea20edcc496b99b1a1d21a520 |
|
MD5 | a19d267c7dbe53b879112f863fee893d |
|
BLAKE2b-256 | 3a82a147e2ad4d1aa683130f8843c776d8f3b51a64b9fface8841bbe5c16597a |