wait_for_element
Wait for a web element to appear using a CSS selector, then extract its content from dynamic pages during web scraping.
Instructions
Wait for an element to appear and extract its content
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | URL to scrape | |
| selector | Yes | CSS selector to wait for | |
| timeout | No | Timeout in milliseconds |
Implementation Reference
- src/scrapers/dynamic-scraper.ts:250-269 (handler)Core handler function that launches a Puppeteer browser, navigates to the URL, waits for the specified selector, extracts and returns the element's text content.async waitForElement(config: ScrapingConfig, selector: string): Promise<string> { const browser = await this.getBrowser(); const page = await browser.newPage(); try { await page.goto(config.url, { waitUntil: 'networkidle', timeout: config.timeout || 30000, }); await page.waitForSelector(selector, { timeout: config.waitForTimeout || 10000, }); const text = await page.textContent(selector); return text || ''; } finally { await page.close(); } }
- src/tools/web-scraping.ts:220-242 (registration)Tool registration object defining the name, description, and input schema for the 'wait_for_element' tool.{ name: 'wait_for_element', description: 'Wait for an element to appear and extract its content', inputSchema: { type: 'object', properties: { url: { type: 'string', description: 'URL to scrape', }, selector: { type: 'string', description: 'CSS selector to wait for', }, timeout: { type: 'number', description: 'Timeout in milliseconds', default: 10000, }, }, required: ['url', 'selector'], }, },
- src/tools/web-scraping.ts:367-371 (handler)Dispatcher handler case in handleWebScrapingTool that extracts parameters and delegates to DynamicScraper.waitForElement.case 'wait_for_element': { const selector = params.selector as string; const content = await dynamicScraper.waitForElement(config, selector); return { selector, content }; }
- src/tools/web-scraping.ts:223-241 (schema)Input schema defining the expected parameters: url, selector, and optional timeout for the tool.inputSchema: { type: 'object', properties: { url: { type: 'string', description: 'URL to scrape', }, selector: { type: 'string', description: 'CSS selector to wait for', }, timeout: { type: 'number', description: 'Timeout in milliseconds', default: 10000, }, }, required: ['url', 'selector'], },