playwright_get_html_content
Extract HTML content from web pages using CSS selectors for web automation and data retrieval tasks.
Instructions
Get the HTML content of the page
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"selector": "<selector>"
},
"name": "playwright_get_html_content"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | CSS selector for the element |
Implementation Reference
- src/playwright_server/server.py:323-332 (handler)The handler class that implements the core logic for the 'playwright_get_html_content' tool. It retrieves the inner HTML content of the specified CSS selector from the current Playwright page session.
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, specifying a required 'selector' field.
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:334-344 (registration)Registration of all tool handlers in a dictionary used by the @server.call_tool() handler to dispatch tool calls.
tool_handlers = { "playwright_navigate": NavigateToolHandler(), "playwright_screenshot": ScreenshotToolHandler(), "playwright_click": ClickToolHandler(), "playwright_fill": FillToolHandler(), "playwright_evaluate": EvaluateToolHandler(), "playwright_click_text": ClickTextToolHandler(), "playwright_get_text_content": GetTextContentToolHandler(), "playwright_get_html_content": GetHtmlContentToolHandler(), "playwright_new_session":NewSessionToolHandler(), }