智能双搜索引擎 - 自动选择最佳搜索引擎


⚠️ This skill requires at least one search engine:
| Variable | Description | Required |
|---|---|---|
| ---------- | ------------- | ---------- |
GOOGLE_API_KEY | Google Custom Search API key | ⚠️ Optional* |
GOOGLE_CX | Google Custom Search Engine ID | ⚠️ Optional* |
BAIDU_API_KEY | Baidu Search API key | ⚠️ Optional* |
*At least one search engine must be configured. Recommended: configure both for best results.
Setup:
# Google (get from https://console.cloud.google.com/)
export GOOGLE_API_KEY="your_google_api_key"
export GOOGLE_CX="your_search_engine_id"
# Baidu (get from https://ai.baidu.com/)
export BAIDU_API_KEY="your_baidu_api_key"
# Or use .env file
cp .env.example .env
# Edit .env and add your API keys
cd ~/.openclaw/workspace/skills/google-baidu-search
# Install dependencies
pip3 install -r requirements.txt
# Copy example .env file
cp .env.example .env
# Edit .env and add your API keys
nano .env
from src.search import search_web
# Auto-select engine (recommended)
result = search_web("人工智能 2026") # Auto-selects Baidu
print(result)
result = search_web("AI trends 2026") # Auto-selects Google
print(result)
# Manual engine selection
result = search_web("AI trends", engine='google', count=10)
result = search_web("人工智能", engine='baidu', count=10)
result = search_web("AI", engine='both', count=10)
# Auto-select engine (recommended)
python3 src/search.py "人工智能 2026" # Auto: Baidu
python3 src/search.py "AI trends 2026" # Auto: Google
# Manual engine selection
python3 src/search.py "AI trends" google 10 # Force Google
python3 src/search.py "人工智能" baidu 10 # Force Baidu
python3 src/search.py "AI" both 10 # Search both
The smart search engine automatically selects the best search engine based on:
| Query | Auto-Selected Engine | Reason |
|---|---|---|
| ------- | --------------------- | -------- |
| "人工智能 2026" | Baidu | Contains Chinese characters |
| "AI trends 2026" | English query | |
| "北京美食" | Baidu | China-related keyword |
| "New York restaurants" | International query | |
| "中文搜索" | Baidu | Chinese keyword |
| "machine learning" | English query |
from src.search import SmartSearch, search_web
# Method 1: Simple search (auto-select)
result = search_web("人工智能 2026")
print(result)
# Method 2: Smart Search client
searcher = SmartSearch()
# Auto-select engine
results = searcher.search("人工智能 2026", engine='auto')
# Force specific engine
results = searcher.search("AI trends", engine='google')
results = searcher.search("人工智能", engine='baidu')
# Search both engines
results = searcher.search("AI", engine='both')
# Check available engines
engines = searcher.get_available_engines()
print(f"Available engines: {engines}")
# Process results
for result in results:
print(f"Title: {result['title']}")
print(f"URL: {result['url']}")
print(f"Source: {result['source']}")
print(f"Engine: {result['engine']}")
print()
google-baidu-search/
├── src/
│ └── search.py # Main search client with smart selection
├── .env.example # Environment variables template
├── requirements.txt # Python dependencies
├── SKILL.md # This file
└── README.md # Documentation
# Chinese news (auto-selects Baidu)
result = search_web("最新科技新闻 2026")
# Global news (auto-selects Google)
result = search_web("latest tech news 2026")
# Chinese academic (auto-selects Baidu)
result = search_web("机器学习论文")
# International academic (auto-selects Google)
result = search_web("machine learning papers")
# Chinese products (auto-selects Baidu)
result = search_web("智能手机评测")
# Global products (auto-selects Google)
result = search_web("smartphone reviews 2026")
# China local (auto-selects Baidu)
result = search_web("北京美食推荐")
# International local (auto-selects Google)
result = search_web("best restaurants New York")
{
"title": "Page Title",
"url": "https://example.com/page",
"snippet": "Page description snippet",
"display_link": "example.com",
"source": "Google" or "Baidu",
"engine": "google" or "baidu"
}
🔍 Search Results for: 人工智能 2026
Engine: Baidu (Auto-selected)
Available engines: google, baidu
Found 10 results:
1. **2026 年人工智能发展趋势** [Baidu]
URL: https://example.com/ai-trends-2026
人工智能领域在 2026 年将继续快速发展...
2. **AI 技术应用前景** [Baidu]
URL: https://example.com/ai-applications
AI 技术在各行业的应用前景广阔...
MIT License - See LICENSE file for details.
Happy Searching! 🔍
Last Updated: 2026-03-19
Version: 1.0.0
Author: PocketAI for Leo
Contact: claw@pocketai.sg
共 1 个版本