AI Selector Repair Tool avatar

AI Selector Repair Tool

Pricing

Pay per event

Go to Apify Store
AI Selector Repair Tool

AI Selector Repair Tool

Fix broken CSS and XPath selectors with AI. Provide a URL and broken selectors โ€” get back updated, working selectors with confidence scores and explanations of what changed in the page structure.

Pricing

Pay per event

Rating

0.0

(0)

Developer

Stas Persiianenko

Stas Persiianenko

Maintained by Community

Actor stats

0

Bookmarked

2

Total users

1

Monthly active users

3 days ago

Last modified

Share

What does AI Selector Repair Tool do?

AI Selector Repair Tool fixes broken CSS and XPath selectors using AI-powered analysis. When a website changes its layout and your scrapers break, this tool takes your broken selectors and the target URL, analyzes the current page structure with an LLM (Claude or GPT), and returns updated working selectors with confidence scores and explanations of what changed.

Instead of manually inspecting HTML diffs and rewriting selectors by hand, let AI handle the tedious work. The tool fetches the current page, sends the HTML and broken selectors to an LLM, and validates that the repaired selectors actually match elements on the page.

Try it now on the Apify platform โ€” no coding required.

Who is AI Selector Repair Tool for?

๐Ÿ”ง Web Scraping Engineers

  • Fix broken scraper selectors without manually inspecting page source
  • Integrate into CI/CD pipelines to auto-repair selectors when scrapers fail
  • Batch-repair multiple selectors from a single broken scraper

๐Ÿ“Š Data Teams

  • Keep data pipelines running when source websites update their layouts
  • Reduce downtime between website changes and scraper fixes
  • Get confidence scores to decide whether to auto-deploy fixes or flag for review

๐Ÿค– Automation Builders

  • Maintain browser automation scripts (Playwright, Puppeteer, Selenium) when target pages change
  • Fix test suite selectors that break after UI updates
  • Build self-healing automation workflows

๐Ÿข Scraper-as-a-Service Providers

  • Reduce maintenance cost across hundreds of scrapers
  • Automate the most common scraper failure mode (selector breakage)
  • Pair with Scraper Regression Watchdog for detect-then-fix pipelines

Why use AI Selector Repair Tool?

  • ๐Ÿง  AI-powered analysis โ€” uses Claude or GPT to understand what the selector was targeting, not just string matching
  • โœ… Validation built in โ€” repaired selectors are tested against the actual page HTML before being returned
  • ๐Ÿ“Š Confidence scores โ€” each repair includes a 0-1 confidence score so you know when to auto-deploy vs. review manually
  • ๐Ÿ’ก Change explanations โ€” understand WHY your selector broke (class renamed, element restructured, etc.)
  • ๐Ÿ”„ CSS and XPath โ€” supports both selector types, with intelligent type detection
  • ๐ŸŒ No login required โ€” works on any publicly accessible page
  • โšก HTTP-first โ€” lightweight HTTP fetching keeps costs low (no browser overhead)
  • ๐Ÿ”— API, scheduling, integrations โ€” run via API, schedule recurring repairs, integrate with 5,000+ apps via Zapier and Make
  • ๐Ÿค Pairs with Watchdog โ€” combine with Scraper Regression Watchdog for automated detect-and-fix workflows

What data can you extract?

AI Selector Repair Tool returns one result per input selector:

FieldTypeDescription
originalSelectorstringThe broken selector you provided
repairedSelectorstringThe AI-suggested fix
selectorTypestringcss or xpath
confidencenumberConfidence score (0-1)
statusstringrepaired, unchanged, or failed
explanationstringWhat changed in the page structure
matchedElementsnumberHow many elements the repaired selector matches
urlstringThe page URL that was analyzed

How much does it cost to repair broken selectors?

AI Selector Repair Tool uses pay-per-event pricing:

EventPrice
Run started$0.01 per run
Selector repaired$0.003 per selector

Example costs:

  • ๐Ÿ”น Repair 5 selectors: $0.01 + (5 ร— $0.003) = $0.025
  • ๐Ÿ”น Repair 20 selectors: $0.01 + (20 ร— $0.003) = $0.07
  • ๐Ÿ”น Repair 100 selectors: $0.01 + (100 ร— $0.003) = $0.31

Note: You also pay for the LLM API calls (Anthropic or OpenAI) using your own API key. Claude Sonnet typically costs $0.003-0.01 per selector depending on HTML size.

With Apify's free plan ($5 monthly credits), you can repair approximately 160 selectors per month (Apify costs only, LLM costs separate).

How to repair broken selectors

  1. Go to AI Selector Repair Tool on Apify
  2. Enter the URL of the page where your selectors are broken
  3. Add your broken selectors to the list (CSS or XPath)
  4. Optionally add descriptions of what each selector targets (improves accuracy)
  5. Enter your Anthropic or OpenAI API key
  6. Click Start and wait for results
  7. Review the repaired selectors, confidence scores, and explanations
  8. Update your scraper code with the new selectors

Example input for Hacker News:

{
"url": "https://news.ycombinator.com",
"selectors": [".storylink", "td.title > a.storylink"],
"selectorDescriptions": ["Story title link", "Story title link (alternative)"],
"anthropicApiKey": "sk-ant-..."
}

Example input for an e-commerce site:

{
"url": "https://example.com/products",
"selectors": [
".product-card .price-tag",
"div.product-listing span.old-price",
"//div[@class='product']//span[@class='discount-badge']"
],
"selectorDescriptions": [
"Product price element",
"Original price (before discount)",
"Discount badge on product cards"
],
"anthropicApiKey": "sk-ant-..."
}

Input parameters

ParameterTypeRequiredDefaultDescription
urlstringYesโ€”URL of the page where selectors are broken
selectorsstring[]Yesโ€”List of broken CSS or XPath selectors
oldHtmlstringNoโ€”Old HTML snapshot for better change detection
selectorDescriptionsstring[]Noโ€”What each selector was supposed to target
anthropicApiKeystring*โ€”Anthropic API key (provide this OR OpenAI key)
openaiApiKeystring*โ€”OpenAI API key (alternative to Anthropic)
modelstringNoclaude-sonnet-4-20250514LLM model to use
maxHtmlLengthnumberNo50000Max HTML chars sent to LLM
proxyConfigurationobjectNoโ€”Proxy settings for fetching the page

*At least one API key (Anthropic or OpenAI) is required.

Output example

[
{
"originalSelector": ".storylink",
"repairedSelector": ".titleline > a",
"selectorType": "css",
"confidence": 0.95,
"status": "repaired",
"explanation": "Hacker News renamed the 'storylink' class to 'titleline' and wrapped it in a span. The link is now a direct child of '.titleline'.",
"matchedElements": 30,
"url": "https://news.ycombinator.com"
},
{
"originalSelector": "td.title > a.storylink",
"repairedSelector": "td.title .titleline > a",
"selectorType": "css",
"confidence": 0.9,
"status": "repaired",
"explanation": "The 'storylink' class was removed. Links are now inside a '.titleline' span within the title cell.",
"matchedElements": 30,
"url": "https://news.ycombinator.com"
}
]

Tips for best results

  • ๐Ÿ“ Add selector descriptions โ€” telling the AI "this selects the product price" dramatically improves accuracy vs. just providing the selector string
  • ๐Ÿ“„ Provide old HTML when possible โ€” if you have a cached copy of the page when selectors worked, include it via oldHtml for much better change detection
  • ๐ŸŽฏ Start with Claude Sonnet โ€” it provides the best accuracy. Switch to Haiku or GPT-4o Mini for bulk repairs where speed matters more than precision
  • ๐Ÿ’ฐ Reduce maxHtmlLength for simple pages โ€” if the target elements are near the top of the page, 10,000-20,000 chars is usually enough
  • โšก Batch related selectors โ€” send all broken selectors for one page in a single run to save on start event costs
  • ๐Ÿ” Check confidence scores โ€” auto-deploy repairs with confidence โ‰ฅ 0.8, manually review anything below
  • ๐Ÿ”„ Pair with Scraper Regression Watchdog โ€” detect breakage automatically, then feed broken selectors into this tool

Integrations

  • ๐Ÿ“Š AI Selector Repair โ†’ Google Sheets โ€” export repaired selectors to a spreadsheet for team review before deploying fixes
  • ๐Ÿ”” Scraper Regression Watchdog โ†’ AI Selector Repair โ†’ Slack โ€” automated pipeline: detect broken scraper, repair selectors, notify team with results
  • ๐Ÿ”„ AI Selector Repair โ†’ Make/Zapier โ€” trigger selector repair when a scraper fails, then auto-update the scraper configuration
  • โฐ Scheduled selector health checks โ€” run weekly on critical scrapers to proactively catch selector drift before it causes failures
  • ๐Ÿ”— Webhooks โ€” get real-time notifications when repairs are complete, trigger downstream scraper updates automatically

Using the Apify API

Node.js

import { ApifyClient } from 'apify-client';
const client = new ApifyClient({ token: 'YOUR_APIFY_TOKEN' });
const run = await client.actor('automation-lab/ai-selector-repair').call({
url: 'https://example.com/products',
selectors: ['.product-card .price', '.old-product-name'],
selectorDescriptions: ['Product price', 'Product name'],
anthropicApiKey: 'sk-ant-...',
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
console.log(items);

Python

from apify_client import ApifyClient
client = ApifyClient("YOUR_APIFY_TOKEN")
run = client.actor("automation-lab/ai-selector-repair").call(run_input={
"url": "https://example.com/products",
"selectors": [".product-card .price", ".old-product-name"],
"selectorDescriptions": ["Product price", "Product name"],
"anthropicApiKey": "sk-ant-...",
})
items = client.dataset(run["defaultDatasetId"]).list_items().items
print(items)

cURL

curl "https://api.apify.com/v2/acts/automation-lab~ai-selector-repair/runs?token=YOUR_APIFY_TOKEN" \
-X POST \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/products",
"selectors": [".product-card .price", ".old-product-name"],
"selectorDescriptions": ["Product price", "Product name"],
"anthropicApiKey": "sk-ant-..."
}'

Use with AI agents via MCP

AI Selector Repair Tool is available as a tool for AI assistants that support the Model Context Protocol (MCP).

Setup for Claude Code

$claude mcp add --transport http apify "https://mcp.apify.com?tools=automation-lab/ai-selector-repair"

Setup for Claude Desktop, Cursor, or VS Code

Add this to your MCP config file:

{
"mcpServers": {
"apify": {
"type": "http",
"url": "https://mcp.apify.com?tools=automation-lab/ai-selector-repair"
}
}
}

Example prompts

  • "My scraper for example.com broke. The selector .product-list .item-price no longer works. Can you fix it?"
  • "Check if these selectors still work on https://news.ycombinator.com: .storylink, .score"
  • "I have 10 broken selectors for my e-commerce scraper. Here they are: [...]. Fix them all and tell me which ones you're confident about."

AI Selector Repair Tool only reads publicly accessible web pages โ€” it does not bypass any authentication, CAPTCHA, or access controls. The tool analyzes page structure to help you maintain your web scrapers.

You should always review the Terms of Service of any website you scrape and ensure your usage complies with applicable laws including GDPR and CCPA. For more information, see Apify's guide on ethical web scraping.

FAQ

How accurate are the repaired selectors? Accuracy depends on the complexity of the page change. For simple class renames or element restructuring, accuracy is typically 85-95%. For major page redesigns, accuracy drops โ€” use the confidence score to gauge reliability. Providing selector descriptions and old HTML significantly improves accuracy.

How much does it cost per repair? Apify charges $0.003 per selector + $0.01 per run. LLM API costs (your own key) add approximately $0.003-0.01 per selector with Claude Sonnet, depending on HTML size. Total cost per selector is typically $0.006-0.013.

Can it fix XPath selectors? Yes. The AI understands both CSS and XPath selectors. However, CSS selector repairs can be validated against the page HTML directly, while XPath repairs rely on the AI's confidence score for validation.

Why are my repaired selectors showing 0 matched elements? This usually means the page requires JavaScript rendering to display the target elements. Try: (1) providing the rendered HTML via oldHtml, (2) using a proxy if the page is geo-restricted, or (3) checking that the URL is correct and the page is publicly accessible.

Why did the confidence score drop to 0.3? A low confidence score (0.3 or below) means the repaired selector was validated against the page HTML but matched 0 elements. This typically indicates the repair needs manual review โ€” the AI found a plausible fix but couldn't confirm it works.

Which LLM model should I use? Claude Sonnet 4 (default) offers the best accuracy. Claude Haiku 4.5 is 3-5x cheaper and still good for straightforward repairs. GPT-4o Mini is comparable to Haiku in both cost and quality. Use the best model for critical selectors, cheaper models for bulk operations.

Other scraper tools