Claude Sonnet 4.6 for Web Scraping and AI Agents: Extended Thinking + Tool Use (2026)
Extended thinking first shipped in Claude 3.7 Sonnet (February 24, 2025), the first hybrid reasoning model from Anthropic. It is now standard across the Claude 4 family, and the model you should actually reach for today is Claude Sonnet 4.6 for balanced agent work or Claude Opus 4.7 when a task needs the strongest reasoning. Extended thinking lets the model reason through multi-step decisions before it acts, which is what makes Claude reliable for autonomous web research.
This guide covers the three main patterns for using Claude in web scraping and data collection workflows. The code works the same whether you point it at Sonnet 4.6 or Opus 4.7. Just swap the model ID.
Which Claude model to use for agents
| Feature | Claude 3.5 Sonnet (legacy) | Claude Sonnet 4.6 | Claude Opus 4.7 |
|---|---|---|---|
| Extended thinking | No | Yes | Yes |
| Tool use accuracy | Good | Excellent | Best |
| Multi-step planning | Basic | Reliable | Strongest |
| Context window | 200K | 1M | 1M |
| Price (API) | $3 / $15 per M tokens | $3 / $15 per M tokens | $5 / $25 per M tokens |
For most scraping agents, Sonnet 4.6 is the right default: same price as the old 3.5 Sonnet, a 1M-token context window, and far better tool use. Reach for Opus 4.7 only when a job needs the deepest reasoning (large multi-source research reports, tricky code generation) and the higher token cost is worth it. New to Claude? You can try it free for a week before committing to a plan.
Extended thinking gives Claude "scratchpad" space to reason through complex multi-step decisions before executing tool calls. That matters for research agents that must plan a scraping strategy before collecting data.
Pattern 1: Claude + Apify MCP Server
The Apify MCP Server connects Claude Desktop to 30,000+ Actors. With extended thinking, Claude can plan a multi-Actor research workflow autonomously.
Setup
The simplest path in 2026 is the hosted server. Add it as a remote connector pointing at https://mcp.apify.com/?fpr=use-apify and authenticate with OAuth on first use. No token to paste, and Actors update automatically.
If you prefer to run it locally, add this to your Claude Desktop config file (~/Library/Application Support/Claude/claude_desktop_config.json on macOS, %APPDATA%\Claude\claude_desktop_config.json on Windows):
{
"mcpServers": {
"apify": {
"command": "npx",
"args": ["-y", "@apify/actors-mcp-server", "--actors", "apify/google-search-scraper,apify/website-content-crawler"],
"env": {
"APIFY_TOKEN": "your_token_here"
}
}
}
}
Start with one or two Actors in the --actors list. Loading the full catalog inflates the tool metadata Claude has to read on every turn and makes routing less accurate. Restart Claude Desktop fully after editing the config.
Example Prompt (Claude Desktop)
"Research the top 10 competitors for [company] in the enterprise SaaS space. For each competitor, find their pricing page, extract pricing tiers, and summarize their positioning vs [company]. Output a comparison table."
Claude with extended thinking will:
- Plan which Actors to use (Google Search scraper, URL-to-Markdown)
- Execute searches to find competitor pricing pages
- Scrape each page via Apify
- Synthesize the comparison table
Pattern 2: Tool Use via Anthropic API
Use the Anthropic API directly to build scraping agents with full control:
import anthropic
import requests
client = anthropic.Anthropic()
# Define tools
tools = [
{
"name": "scrape_url",
"description": "Scrape a URL and return the page content as Markdown text.",
"input_schema": {
"type": "object",
"properties": {
"url": {
"type": "string",
"description": "The URL to scrape"
}
},
"required": ["url"]
}
},
{
"name": "search_web",
"description": "Search the web for a query and return a list of URLs.",
"input_schema": {
"type": "object",
"properties": {
"query": {"type": "string"},
"num_results": {"type": "integer", "default": 5}
},
"required": ["query"]
}
}
]
def execute_tool(tool_name, tool_input):
if tool_name == "scrape_url":
# Use Firecrawl for clean Markdown
resp = requests.post(
"https://api.firecrawl.dev/v1/scrape",
json={"url": tool_input["url"], "formats": ["markdown"]},
headers={"Authorization": f"Bearer {FIRECRAWL_KEY}"}
)
return resp.json().get("data", {}).get("markdown", "")
elif tool_name == "search_web":
# Use Apify Google Search scraper
run = requests.post(
"https://api.apify.com/v2/acts/apify~google-search-scraper/runs",
json={"queries": tool_input["query"], "maxPagesPerQuery": 1},
headers={"Authorization": f"Bearer {APIFY_TOKEN}"}
)
# ... fetch results
return []
# Agentic loop with extended thinking
def research_agent(task: str) -> str:
messages = [{"role": "user", "content": task}]
while True:
response = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=16000,
thinking={"type": "enabled", "budget_tokens": 10000},
tools=tools,
messages=messages
)
if response.stop_reason == "end_turn":
# Extract final text response
for block in response.content:
if block.type == "text":
return block.text
# Process tool calls
tool_results = []
for block in response.content:
if block.type == "tool_use":
result = execute_tool(block.name, block.input)
tool_results.append({
"type": "tool_result",
"tool_use_id": block.id,
"content": str(result)
})
# Continue conversation with tool results
messages.append({"role": "assistant", "content": response.content})
messages.append({"role": "user", "content": tool_results})
result = research_agent("Find the pricing for Apify, Bright Data, and Firecrawl. Return a comparison table.")
print(result)
Pattern 3: Claude Generates Python Scrapers
Claude is highly capable at generating working Playwright/Crawlee scrapers from a description, and Opus 4.7 is the strongest of the lineup for this kind of code generation:
prompt = """
Write a Python Playwright scraper that:
1. Goes to https://target.com/products
2. Waits for the product grid to load
3. Extracts: product name, price, SKU from each card
4. Follows pagination until no next button
5. Outputs data as JSON to stdout
Include error handling and retry logic.
"""
Claude with extended thinking will produce production-quality code with proper:
- Selector fallbacks
- Retry logic
- Pagination handling
- Error logging
See example: Claude generates Python scrapers with Apify
Extended Thinking Best Practices for Scraping Agents
- Set thinking budget:
"budget_tokens": 5000–20000for web research tasks - Specify output format: ask for JSON or Markdown tables, which reduces hallucinations
- Ground with URLs: Provide starting URLs when possible; Claude plans better with concrete inputs
- Cap tool iterations: Add "Do not make more than 20 tool calls" to prevent runaway agents
- Log thinking blocks: Extended thinking content is returned, so log it for debugging
Cost Estimate
| Use Case | API calls | Estimated cost |
|---|---|---|
| 1 competitor research task | ~10 tool calls + synthesis | $0.10–$0.30 |
| Daily price monitor (10 products) | ~20 tool calls | $0.05–$0.15 |
| Full market research report | ~50 tool calls + long context | $1–$3 |
Claude Sonnet 4.6 is priced at $3/M input tokens and $15/M output tokens, the same as the old 3.5 and 3.7 Sonnet but with a 1M-token context window. Opus 4.7 runs $5/$25 per M tokens when you need the extra reasoning. Confirm current rates on the Anthropic pricing page before running at scale.
