AI-Scraper
了解如何使用 AI Studio 从单个 URL 获取网页数据,用于你的 AI 工作流。
最后更新于
这有帮助吗?
这有帮助吗?
pip install oxylabs-ai-studiofrom oxylabs_ai_studio.apps.ai_scraper import AiScraper
import json
# Initialize the AI Scraper with your API key
scraper = AiScraper(api_key="YOUR_API_KEY")
# 从自然语言自动生成 schema
schema = scraper.generate_schema(prompt="want to parse developer, platform, type, price game title, and genre (array)")
print(f"Generated schema: {schema}")
# Scrape a webpage and extract structured data
url = "https://sandbox.oxylabs.io/products/3"
result = scraper.scrape(
url=url,
output_format="json",
schema=schema,
render_javascript=False,
geo_location="US",
)
# Print the scrape output as JSON
print("Results:")
print(json.dumps(result.data, indent=2)){
"games": [
{
"developer": "Nintendo EAD Tokyo",
"platform": "wii",
"type": "singleplayer",
"price": 91.99,
"title": "Super Mario Galaxy 2",
"genre": [
"Action",
"Platformer"
]
},
{
"developer": "Eidos Interactive",
"platform": "wii",
"type": null,
"price": 80.99,
"title": "Death Jr.: Root of Evil",
"genre": [
"Action",
"Platformer",
"3D"
]
}
}