Skip to content

itbanque/talk2dom-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Talk2Dom Python SDK

PyPI PyPI Downloads Stars License CI

Minimal client SDK to call the Talk2Dom API.

Install

pip install talk2dom
# optional
pip install "talk2dom[selenium]"
# or
pip install "talk2dom[playwright]"
## Quiack Start
from talk2dom import Talk2DomClient

client = Talk2DomClient(
  api_key="YOUR_API_KEY",
  project_id="YOUR_PROJECT_ID",
)

# sync example
res = client.locate("click the primary login button", html="<html>...</html>", url="https://example.com")

# async exmaple
res = client.alocate("click the primary login button", html="<html>...</html>", url="https://example.com")

Environment variables

Selenium ActionChains

from selenium import webdriver

import time
from talk2dom.selenium import ActionChains

driver = webdriver.Chrome()

driver.get("https://python.org")

actions = ActionChains(driver)

actions\
    .go("Type 'pycon' in the search box")\
    .go("Click the 'go' button")

time.sleep(2)

Playwright PageNavigator

from playwright.sync_api import sync_playwright
from talk2dom.playwright import PageNavigator


def main():
    with sync_playwright() as p:
        # Launch Chromium browser
        browser = p.chromium.launch(headless=False)
        page = browser.new_page()

        navigator = PageNavigator(page)

        # Navigate to python.org
        page.goto("https://www.python.org")

        navigator.go("Type 'pycon' in the search box")

        navigator.go("Click the 'go' button")

        # Wait for results to load
        page.wait_for_timeout(3000)

        # Close the browser
        browser.close()


if __name__ == "__main__":
    main()