playwright_get_html_content
Extract HTML content from a webpage using a CSS selector. This tool, part of the Playwright Server, simplifies retrieving specific HTML elements for automation or analysis.
Instructions
Get the HTML content of the page
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | CSS selector for the element |
Input Schema (JSON Schema)
{
"properties": {
"selector": {
"description": "CSS selector for the element",
"type": "string"
}
},
"required": [
"selector"
],
"type": "object"
}
Implementation Reference
- src/playwright_server/server.py:323-332 (handler)This class implements the core logic for the 'playwright_get_html_content' tool, retrieving the inner HTML content of the specified selector using Playwright's page.locator().inner_html() method.class GetHtmlContentToolHandler(ToolHandler): async def handle(self, name: str, arguments: dict | None) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]: if not self._sessions: return [types.TextContent(type="text", text="No active session. Please create a new session first.")] session_id = list(self._sessions.keys())[-1] page = self._sessions[session_id]["page"] selector = arguments.get("selector") html_content = await page.locator(selector).inner_html() return [types.TextContent(type="text", text=f"HTML content of element with selector {selector}: {html_content}")]
- JSON schema definition for the tool's input parameters as returned by list_tools(), specifying a required 'selector' string property.types.Tool( name="playwright_get_html_content", description="Get the HTML content of the page", inputSchema={ "type": "object", "properties": { "selector": {"type": "string", "description": "CSS selector for the element"} }, "required": ["selector"] } )
- src/playwright_server/server.py:342-342 (registration)The tool handler instance is registered in the tool_handlers dictionary, which maps tool names to their handlers and is used in the @server.call_tool() implementation."playwright_get_html_content": GetHtmlContentToolHandler(),