Skip to content

API Reference parrot_tools.scraping.models

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_tools.scraping.models

View source

Browser Action System for AI-Parrot WebScrapingTool Object-oriented action hierarchy for LLM-directed browser automation

Attribute ACTION_MAP

Attribute ActionList

Class Authenticate

Handle authentication flows

Attributes:

Attribute Type Description
name str
action Literal['authenticate']
description str
method Literal['form', 'basic', 'oauth', 'custom']
username Optional[str]
password Optional[str]
credential_provider Optional[str]
username_selector str
enter_on_username bool
password_selector str
submit_selector str
custom_steps Optional[List[BrowserAction]]
token Optional[str]
header_name str
header_value_format str

Class AwaitBrowserEvent

Wait for human interaction in the browser

Attributes:

Attribute Type Description
name str
action Literal['await_browser_event']
target Optional[Union[str, Dict[str, Any]]]
description str
wait_condition Dict[str, Any]
timeout int

Method AwaitBrowserEvent.get_action_type

get_action_type() -> str

Returns: str

Class AwaitHuman

Pause and wait for human intervention

Attributes:

Attribute Type Description
name str
action Literal['await_human']
description str
target Optional[str]
condition_type Literal['selector', 'url_contains', 'title_contains', 'manual']
message str
timeout int

Class AwaitKeyPress

Wait for human to press a key in console

Attributes:

Attribute Type Description
name str
action Literal['await_keypress']
description str
expected_key Optional[str]
message str
timeout int

Class Back

Navigate back to the previous page

Attributes:

Attribute Type Description
name str
action Literal['back']
description str
steps int

Class BrowserAction

Base class for all browser actions

Fields:

Field Type Default Description
name str '' Optional name for this action
action str '' Action opcode used for union discrimination
description str '' Human-readable description of this action
timeout Optional[int] None Maximum time to wait for action completion (seconds), None for no wait.

Method BrowserAction.get_action_type

Return the action type identifier used for dispatch.

Reads self.action — the Literal-discriminated opcode set by each subclass ("navigate", "click", "scroll", ...). The name field is a free-form label (LLMs often set it to describe the step, e.g. "prepaid_plans") and MUST NOT be used for dispatch. Falls back to name if action is empty, for backwards compatibility with plans built before this fix.

get_action_type() -> str

Returns: str

Attribute BrowserActionTypeAdapter

Type: TypeAdapter[Any]

Attribute BrowserActionUnion

Class Click

Click on a web page element

Attributes:

Attribute Type Description
name str
action Literal['click']
selector str
description str
selector_type Literal['css', 'xpath', 'text']
click_type Literal['single', 'double', 'right']
wait_after_click Optional[str]
wait_timeout int
no_wait bool

Class Conditional

Execute actions conditionally based on a JavaScript expression

Attributes:

Attribute Type Description
name str
action Literal['conditional']
description str
target Optional[str]
target_type Literal['css', 'xpath']
condition_type Literal['text_contains', 'exists', 'not_exists', 'text_equals', 'attribute_equals']
expected_value str
timeout int
actions_if_true Optional[List['ActionList']]
actions_if_false Optional[List['ActionList']]

Class Evaluate

Execute JavaScript code in the browser context

Attributes:

Attribute Type Description
name str
action Literal['evaluate']
description str
script Optional[str]
script_file Optional[str]
args List[Any]
return_value bool

Method Evaluate.validate_script_source

Ensure either script or script_file is provided, but not both

validate_script_source(v, info)

Parameter Type Default Description
v
info

Class Extract

Extract data from the page using CSS selectors or XPath.

Two usage shapes:

  1. Flat (single value): {action: "extract", selector: ".price", extract_type: "text", extract_name: "price"} — writes extracted_data["price"].

  2. Row-of-fields (LLM-friendly): set fields to a dict of {column_name: FieldSpec}. The parent selector picks row elements (use multiple: true for lists); each field selector runs RELATIVE to its row. Result: a list of dicts keyed by field names, written to extracted_data[extract_name or name].

Attributes:

Attribute Type Description
name str
action Literal['extract']
description str
selector str
selector_type Literal['css', 'xpath']
extract_type Literal['html', 'text', 'attribute']
attribute Optional[str]
multiple bool
extract_name str
fields Optional[Dict[str, FieldSpec]]

Class ExtractJsonLd

Extract structured data from JSON-LD blocks on the current page.

Iterates every <script type="application/ld+json"> block, walks the JSON graph (descending into @graph and arrays), and dispatches typed nodes through the shared EXTRACTOR_REGISTRY from parrot.utils.jsonld_extractors. Result is a flat list of dicts, one per extracted JsonLdItem, written to step_extracted[extract_name].

Two filtering modes:

  • types=None (default): extract every registered @type.
  • types=["Product", "Recipe"]: only those types.

Attributes:

Attribute Type Description
name str
action Literal['extract_jsonld']
description str
extract_name str
types Optional[List[str]]

Class FieldSpec

One sub-selector for a row-of-fields Extract step.

Applied RELATIVE to each row element matched by the parent Extract's selector. Use this to describe the columns of a repeating block (e.g. for each plan card: name, price, data, CTA).

Fields:

Field Type Default Description
selector str CSS or XPath selector relative to the row element
selector_type Literal['css', 'xpath'] 'css'
extract_type Literal['text', 'html', 'attribute'] 'text' What to extract: 'text' (default), 'html', or 'attribute'
attribute Optional[str] None Attribute name when extract_type='attribute' (e.g. 'href', 'src'). Convenience: set attribute='text' or 'html' and leave extract_type at default — the value will be auto-promoted to extract_type.
multiple bool False Return a list of matches within the row instead of the first.

Class Fill

Fill text into an input field

Attributes:

Attribute Type Description
name str
action Literal['fill']
description str
selector str
value str
clear_first bool
press_enter bool

Class GetCookies

Extract and evaluate cookies

Attributes:

Attribute Type Description
name str
action Literal['get_cookies']
description str
names Optional[List[str]]
domain Optional[str]

Class GetHTML

Extract complete HTML content from elements matching selector

Attributes:

Attribute Type Description
name str
action Literal['get_html']
description str
selector str
selector_type Literal['css', 'xpath']
multiple bool
extract_name str

Class GetText

Extract pure text content from elements matching selector

Attributes:

Attribute Type Description
name str
action Literal['get_text']
description str
selector str
multiple bool
extract_name str

Class Hover

Move the mouse over an area/element

Attributes:

Attribute Type Description
name str
action Literal['hover']
description str
selector str
selector_type Literal['css', 'xpath', 'text']

Class Loop

Repeat a sequence of actions multiple times

Attributes:

Attribute Type Description
name str
action Literal['loop']
description str
actions List['ActionList']
iterations Optional[int]
condition Optional[str]
values Optional[List[Any]]
value_name Optional[str]
break_on_error bool
max_iterations int
start_index int
do_replace bool

Class Navigate

Navigate to a URL

Attributes:

Attribute Type Description
name str
action Literal['navigate']
url str
description str

Class PressKey

Press keyboard keys

Attributes:

Attribute Type Description
name str
action Literal['press_key']
description str
keys List[str]
sequential bool
target Optional[str]

Class Refresh

Reload the current web page

Attributes:

Attribute Type Description
name str
action Literal['refresh']
description str
hard bool

Class ScrapingResult

Stores results from a single page scrape

Parameter Type Default Description
url str
content str
bs_soup BeautifulSoup
extracted_data Dict[str, Any] dict()
metadata Dict[str, Any] dict()
timestamp str ''
success bool True
error_message Optional[str] None

Fields:

Field Type Default Description
url str
content str
bs_soup BeautifulSoup
extracted_data Dict[str, Any] field(default_factory=dict)
metadata Dict[str, Any] field(default_factory=dict)
timestamp str ''
success bool True
error_message Optional[str] None

Class ScrapingSelector

Defines what content to extract from a page

Parameter Type Default Description
name str
selector str
selector_type Literal['css', 'xpath', 'tag'] 'css'
extract_type Literal['text', 'html', 'attribute'] 'text'
attribute Optional[str] None
multiple bool False

Fields:

Field Type Default Description
name str
selector str
selector_type Literal['css', 'xpath', 'tag'] 'css'
extract_type Literal['text', 'html', 'attribute'] 'text'
attribute Optional[str] None
multiple bool False

Class ScrapingStep

ScrapingStep that wraps a BrowserAction.

Used to define a step in a scraping sequence.

Parameter Type Default Description
action BrowserAction
description str ''

Fields:

Field Type Default Description
action BrowserAction
description str field(default='')

Method ScrapingStep.to_dict

Convert to dictionary for serialization

to_dict() -> Dict[str, Any]

Returns: Dict[str, Any]

Method ScrapingStep.from_dict

Create ScrapingStep from dictionary

from_dict(data: Dict[str, Any]) -> 'ScrapingStep'

Parameter Type Default Description
data Dict[str, Any]

Returns: 'ScrapingStep'

Class Screenshot

Take a screenshot of the page or a specific element

Attributes:

Attribute Type Description
name str
action Literal['screenshot']
description str
selector Optional[str]
full_page bool
output_path Optional[str]
output_name Optional[str]
return_base64 bool

Method Screenshot.get_filename

Generate a filename for the screenshot

get_filename() -> str

Returns: str

Class Scroll

Scroll the page or an element

Attributes:

Attribute Type Description
name str
action Literal['scroll']
description str
direction Literal['up', 'down', 'top', 'bottom']
amount Optional[int]
selector Optional[str]
smooth bool

Class Select

Select an option from a dropdown/select element.

Attributes:

Attribute Type Description
name str
action Literal['select']
description str
selector str
value Optional[str]
text Optional[str]
index Optional[int]
by Literal['value', 'text', 'index']
blur_after bool
wait_after_select Optional[str]
wait_timeout int

Method Select.validate_selection_params

Ensure at least one selection parameter is provided

validate_selection_params(v, info)

Parameter Type Default Description
v
info

Class SetCookies

Set cookies on the current page or domain

Attributes:

Attribute Type Description
name str
action Literal['set_cookies']
description str
cookies List[Dict[str, Any]]

Class Submit

Click on a submit button or submit a form

Attributes:

Attribute Type Description
name str
action Literal['submit']
description str
selector str
wait_after_submit Optional[str]
wait_timeout int

Class Type

Send keystrokes to the page or an element

Attributes:

Attribute Type Description
name str
action Literal['type']
description str
text str
selector Optional[str]
delay int
clear_first bool

Class UploadFile

Upload a file to a file input element

Attributes:

Attribute Type Description
name str
action Literal['upload_file']
description str
selector str
file_path str
wait_after_upload Optional[str]
wait_timeout int
multiple_files bool
file_paths Optional[List[str]]

Class Wait

Wait for a condition to be met.

Accepts condition (canonical) or selector (LLM-friendly alias) — they mean the same thing when condition_type='selector'.

Attributes:

Attribute Type Description
name str
action Literal['wait']
description str
condition Optional[str]
condition_type Literal['simple', 'selector', 'url_contains', 'url_is', 'title_contains', 'custom']
custom_script Optional[str]
timeout int

Class WaitForDownload

Wait for a file download to complete

Attributes:

Attribute Type Description
name str
action Literal['wait_for_download']
description str
filename_pattern Optional[str]
download_path Optional[str]
timeout int
move_to Optional[str]
delete_after bool

Function create_action

Factory function to create actions by type name Useful for LLM-generated action sequences

create_action(action_type: str, **kwargs) -> BrowserAction

Parameter Type Default Description
action_type str
**kwargs {}

Returns: BrowserAction

Function lint_literal_credentials

Flag any authenticate step in steps carrying a literal password.

A plans-directory lint (FEAT-453 Module 4, Goal G3): credentials must never enter plan JSON — the external, private plans directory (Module 6) is a file the engine merely reads, so a literal password there is a secret at rest. Intended to be run over every plan file in that directory before it is loaded.

lint_literal_credentials(steps: List[Dict[str, Any]]) -> List[str]

Parameter Type Default Description
steps List[Dict[str, Any]] Raw step dicts, as stored in ScrapingPlan.steps (untyped at rest — this lint does not require validate_steps()).

Returns: List[str] — One warning message per offending step (step index named, never the credential value itself). An empty list means the plan is clean.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally