Strategy Methods
Strategy methods allow you to create and manage AI-generated extraction strategies. See the MeterClient reference for complete method signatures.
Quick reference
| Method | Description |
|---|
generate_strategy() | Generate a new extraction strategy using AI |
refine_strategy() | Improve an existing strategy with feedback |
list_strategies() | List all strategies |
get_strategy() | Get details for a specific strategy |
delete_strategy() | Delete a strategy and associated data |
Common workflows
Generate and refine
from meter_sdk import MeterClient
client = MeterClient(api_key="sk_live_...")
# Generate initial strategy
result = client.generate_strategy(
url="https://shop.com/products",
description="Extract product name, price, and image",
name="Product Scraper"
)
# Check preview
print(result['preview_data'][:3])
# Refine if needed
if 'sku' not in result['preview_data'][0]:
refined = client.refine_strategy(
strategy_id=result['strategy_id'],
feedback="Also extract the product SKU"
)
print(refined['preview_data'][:3])
API-based scraping
For sites that load data via JavaScript APIs, use force_api=True to capture the underlying API:
# Force API-based capture
result = client.generate_strategy(
url="https://api-heavy-site.com/listings",
description="Extract all listing data",
name="Listings API Scraper",
force_api=True
)
# Check scraper type
print(f"Scraper type: {result['scraper_type']}") # 'api' or 'css'
# For API strategies, available parameters are returned
if result.get('api_parameters'):
print(f"Available parameters: {result['api_parameters']}")
# e.g., {'page': 1, 'limit': 20, 'category': 'all'}
API-based strategies capture underlying API calls instead of using CSS selectors.
This is useful for dynamic sites where data is loaded via JavaScript.
List and filter
# Get all strategies
strategies = client.list_strategies()
# Find by name
product_strategies = [
s for s in strategies
if 'product' in s['name'].lower()
]
# Most recent
recent = client.list_strategies(limit=5, offset=0)
Batch operations
# Delete old strategies
strategies = client.list_strategies(limit=100)
for strategy in strategies:
# Delete if created more than 30 days ago
if is_old(strategy['created_at']):
client.delete_strategy(strategy['strategy_id'])
print(f"Deleted {strategy['name']}")
See also
Need help?
Email me at mckinnon@meter.sh