Skip to content

Commit cd092dd

Browse files
committed
docs: migrate use-case examples to v2 SDK methods
Replace legacy v1 code snippets in all use-case pages with actual v2 method names and parameters so examples match the current SDK behavior. Made-with: Cursor
1 parent 740b612 commit cd092dd

6 files changed

Lines changed: 62 additions & 67 deletions

File tree

use-cases/ai-llm.mdx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ class ArticleSchema(BaseModel):
3333
summary: Optional[str] = Field(description="Article summary or description")
3434

3535
# Initialize the client
36-
client = Client()
36+
client = Client(api_key="your-api-key")
3737

3838
try:
3939
# Scrape relevant content
40-
response = client.smartscraper(
41-
website_url="https://example.com/article",
42-
user_prompt="Extract the main article content, title, author, and publication date",
40+
response = client.extract(
41+
url="https://example.com/article",
42+
prompt="Extract the main article content, title, author, and publication date",
4343
output_schema=ArticleSchema
4444
)
4545

@@ -72,15 +72,14 @@ class ResearchResults(BaseModel):
7272
articles: List[ResearchData]
7373

7474
# Initialize the client
75-
client = Client()
75+
client = Client(api_key="your-api-key")
7676

7777
try:
7878
# Search and scrape multiple sources
79-
search_results = client.searchscraper(
80-
user_prompt="What are the latest developments in artificial intelligence?",
79+
search_results = client.search(
80+
query="What are the latest developments in artificial intelligence?",
8181
output_schema=ResearchResults,
82-
num_results=5, # Number of websites to search (3-20)
83-
extraction_mode=True # Use AI extraction mode for structured data
82+
num_results=5
8483
)
8584

8685
# Process with your AI model

use-cases/content-aggregation.mdx

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class NewsAggregationResult(BaseModel):
4343
sources: List[str] = Field(description="List of source URLs")
4444
timestamp: str = Field(description="Aggregation timestamp")
4545

46-
client = Client()
46+
client = Client(api_key="your-api-key")
4747

4848
# Define news sources to aggregate
4949
news_sources = [
@@ -56,9 +56,9 @@ news_sources = [
5656
aggregated_results = []
5757

5858
for source in news_sources:
59-
response = client.smartscraper(
60-
website_url=source,
61-
user_prompt="Extract all news articles from the homepage, including title, content, author, publication date, category, and tags. Also extract featured images if available.",
59+
response = client.extract(
60+
url=source,
61+
prompt="Extract all news articles from the homepage, including title, content, author, publication date, category, and tags. Also extract featured images if available.",
6262
output_schema=NewsAggregationResult
6363
)
6464
aggregated_results.append(response)
@@ -110,50 +110,47 @@ class BlogMonitorResult(BaseModel):
110110
blog_url: str = Field(description="Blog homepage URL")
111111
last_updated: str = Field(description="Last monitoring timestamp")
112112

113-
client = Client()
113+
client = Client(api_key="your-api-key")
114114

115115
# Start the crawler job
116-
job = client.smartcrawler_initiate(
116+
job = client.crawl.start(
117117
url="https://example-blog.com",
118-
user_prompt="Extract all blog posts from the last 7 days, including title, content, author, publication date, categories, and metadata. Calculate estimated reading time based on content length.",
119-
extraction_mode="ai",
120118
depth=2, # Crawl up to 2 levels deep
121-
same_domain_only=True
119+
include_patterns=["/blog/*"],
120+
exclude_patterns=["/tag/*", "/author/*"]
122121
)
123122

124123
# Wait for job completion and get results
125-
job_id = job.job_id
124+
job_id = job["id"]
126125
while True:
127-
status = client.smartcrawler_get_status(job_id)
128-
if status.state == "completed":
129-
response = status.result
126+
status = client.crawl.status(job_id)
127+
if status.get("status") == "completed":
128+
response = status.get("data", {})
130129
break
131-
elif status.state in ["failed", "cancelled"]:
132-
print(f"Job failed: {status.error}")
130+
elif status.get("status") in ["failed", "cancelled", "error"]:
131+
print(f"Job failed: {status.get('error')}")
133132
break
134133
time.sleep(5) # Wait 5 seconds before checking again
135134

136135
# Process the crawled content if successful
137-
if response:
138-
print(f"Blog: {response.blog_url}")
139-
print(f"Total Posts Found: {response.total_posts}")
140-
print(f"Last Updated: {response.last_updated}\n")
136+
if response and response.get("pages"):
137+
print(f"Total Pages Found: {len(response['pages'])}")
141138

142-
for post in response.posts:
139+
for post in response["pages"]:
143140
# Check if post is recent
144-
post_date = datetime.strptime(post.publication_date, "%Y-%m-%d")
141+
post_date = datetime.strptime(post["publication_date"], "%Y-%m-%d")
145142
if post_date > datetime.now() - timedelta(days=7):
146-
print(f"Title: {post.title}")
147-
print(f"Author: {post.author}")
148-
print(f"Published: {post.publication_date}")
149-
print(f"Reading Time: {post.reading_time} minutes")
150-
if post.categories:
151-
print(f"Categories: {', '.join(post.categories)}")
152-
if post.tags:
153-
print(f"Tags: {', '.join(post.tags)}")
154-
if post.excerpt:
155-
print(f"\nExcerpt: {post.excerpt}")
156-
print(f"URL: {post.url}\n")
143+
print(f"Title: {post['title']}")
144+
print(f"Author: {post.get('author', 'Unknown')}")
145+
print(f"Published: {post['publication_date']}")
146+
print(f"Reading Time: {post.get('reading_time', 'N/A')} minutes")
147+
if post.get("categories"):
148+
print(f"Categories: {', '.join(post['categories'])}")
149+
if post.get("tags"):
150+
print(f"Tags: {', '.join(post['tags'])}")
151+
if post.get("excerpt"):
152+
print(f"\nExcerpt: {post['excerpt']}")
153+
print(f"URL: {post['url']}\n")
157154
```
158155

159156
## Best Practices

use-cases/lead-generation.mdx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ class CompanyContacts(BaseModel):
3939
client = Client(api_key="your-api-key")
4040

4141
# Scrape company website
42-
response = client.smartscraper(
43-
website_url="https://company.com/about",
44-
user_prompt="Extract all contact information for decision makers and leadership team",
42+
response = client.extract(
43+
url="https://company.com/about",
44+
prompt="Extract all contact information for decision makers and leadership team",
4545
output_schema=CompanyContacts
4646
)
4747

@@ -79,11 +79,10 @@ client = Client(api_key="your-api-key")
7979

8080
try:
8181
# Search for businesses in a specific category
82-
search_results = client.searchscraper(
83-
user_prompt="Find software companies in San Francisco with their contact details",
82+
search_results = client.search(
83+
query="Find software companies in San Francisco with their contact details",
8484
output_schema=BusinessSearchResults,
85-
num_results=10, # Number of websites to search (3-20)
86-
extraction_mode=True # Use AI extraction mode for structured data
85+
num_results=10
8786
)
8887

8988
# Extract and validate leads
@@ -94,9 +93,9 @@ try:
9493

9594
try:
9695
# Get more detailed information from company website
97-
details = client.smartscraper(
98-
website_url=business.website,
99-
user_prompt="Extract detailed company information including team size, tech stack, and all contact methods",
96+
details = client.extract(
97+
url=business.website,
98+
prompt="Extract detailed company information including team size, tech stack, and all contact methods",
10099
output_schema=CompanyContacts # Defined earlier in the file
101100
)
102101

use-cases/market-intelligence.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ class PriceMonitorResult(BaseModel):
4343
client = Client()
4444

4545
# Monitor competitor prices
46-
response = client.smartscraper(
47-
website_url="https://competitor-store.com/category/products",
48-
user_prompt="Extract pricing information for all products including name, current price, original price if available, and availability status",
46+
response = client.extract(
47+
url="https://competitor-store.com/category/products",
48+
prompt="Extract pricing information for all products including name, current price, original price if available, and availability status",
4949
output_schema=PriceMonitorResult
5050
)
5151

@@ -86,8 +86,8 @@ class TrendAnalysisResult(BaseModel):
8686
client = Client()
8787

8888
# Search and analyze market trends
89-
response = client.searchscraper(
90-
user_prompt="Analyze market trends and sentiment in the electric vehicle industry. Focus on pricing trends, consumer preferences, and technological advancements.",
89+
response = client.search(
90+
query="Analyze market trends and sentiment in the electric vehicle industry. Focus on pricing trends, consumer preferences, and technological advancements.",
9191
num_results=10, # Number of sources to analyze
9292
output_schema=TrendAnalysisResult
9393
)

use-cases/research-analysis.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ class ResearchCollectionResult(BaseModel):
4747
client = Client()
4848

4949
# Search and collect research papers
50-
response = client.searchscraper(
51-
user_prompt="Find recent research papers on machine learning applications in healthcare, focusing on papers published in the last year. Extract complete paper details including abstract, citations, and DOI.",
50+
response = client.search(
51+
query="Find recent research papers on machine learning applications in healthcare, focusing on papers published in the last year. Extract complete paper details including abstract, citations, and DOI.",
5252
num_results=15, # Number of papers to collect
5353
output_schema=ResearchCollectionResult
5454
)
@@ -115,9 +115,9 @@ class IndustryAnalysis(BaseModel):
115115
client = Client()
116116

117117
# Collect industry analysis data
118-
response = client.smartscraper(
119-
website_url="https://industry-research-site.com/sector-analysis",
120-
user_prompt="Extract comprehensive industry analysis including detailed market metrics, company profiles, trends, and regulatory factors. Focus on quantitative data where available.",
118+
response = client.extract(
119+
url="https://industry-research-site.com/sector-analysis",
120+
prompt="Extract comprehensive industry analysis including detailed market metrics, company profiles, trends, and regulatory factors. Focus on quantitative data where available.",
121121
output_schema=IndustryAnalysis
122122
)
123123

use-cases/seo-analytics.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ target_keywords = [
6363

6464
for keyword in target_keywords:
6565
# Analyze SERP data
66-
response = client.smartscraper(
67-
website_url=f"https://www.google.com/search?q={keyword}",
68-
user_prompt="Extract detailed search results including positions, titles, descriptions, and all rich results. Also analyze ad presence and total result counts.",
66+
response = client.extract(
67+
url=f"https://www.google.com/search?q={keyword}",
68+
prompt="Extract detailed search results including positions, titles, descriptions, and all rich results. Also analyze ad presence and total result counts.",
6969
output_schema=SERPAnalysis
7070
)
7171

@@ -151,9 +151,9 @@ target_urls = [
151151

152152
for url in target_urls:
153153
# Extract content metrics
154-
response = client.smartscraper(
155-
website_url=url,
156-
user_prompt="Perform comprehensive content analysis including meta tags, headings structure, internal/external links, and structured data. Calculate content quality score based on best practices.",
154+
response = client.extract(
155+
url=url,
156+
prompt="Perform comprehensive content analysis including meta tags, headings structure, internal/external links, and structured data. Calculate content quality score based on best practices.",
157157
output_schema=ContentMetrics
158158
)
159159

0 commit comments

Comments
 (0)