# Capacity Web Search
网络搜索功能包,提供简单易用的网络搜索接口。
## 🚀 快速开始
### 安装
```bash
pip install capacity-web
```
### 使用
```python
from capacity_web import search_web
# 基础搜索
result = search_web("人工智能最新发展")
if result["success"]:
print(f"找到 {result['data']['number_of_results']} 条结果")
for item in result["data"]["results"]:
print(f"标题: {item['title']}")
print(f"链接: {item['url']}")
print(f"摘要: {item['content'][:100]}...")
print(f"评分: {item['score']}")
print("---")
# 高级搜索
result = search_web(
"Python教程",
language="zh",
max_results=10,
categories=["general"],
time_range="year"
)
```
## 📋 API 文档
### search_web(query, language="all", max_results=None, **kwargs)
进行网络搜索。
**参数:**
- `query` (str): 搜索关键词,必填
- `language` (str): 语言代码,默认 "all"
- `max_results` (int): 最大结果数量,1-100之间
- `**kwargs`: 高级选项
**返回:**
```python
{
"success": bool, # 是否成功
"data": { # 搜索结果数据
"query": str, # 查询词
"number_of_results": int, # 结果数量
"results": [ # 搜索结果列表
{
"url": str, # 网页链接
"title": str, # 网页标题
"content": str, # 内容摘要
"engine": str, # 搜索引擎
"score": float, # 相关性评分
"category": str, # 结果类别
# ...更多字段
}
],
"answers": list, # 直接答案
"suggestions": list, # 搜索建议
"corrections": list, # 查询纠正
"infoboxes": list, # 信息框
"unresponsive_engines": list # 无响应引擎
},
"message": str # 状态信息
}
```
## ✨ 特性
- **统一返回格式**: 所有API都返回 `{"success": bool, "data": dict, "message": str}` 格式
- **自动重试**: 网络异常时自动重试,最多3次,指数退避
- **完整错误处理**: 捕获所有网络、HTTP、验证错误
- **AI友好**: 简洁的API设计,易于理解和使用
- **类型提示**: 完整的类型注解支持
## 🔧 高级选项
```python
result = search_web(
"搜索词",
language="zh", # 语言: "zh", "en", "all" 等
max_results=20, # 最大结果数
page_number=1, # 页码
categories=["general", "news"], # 搜索类别
search_engines=["google", "bing"], # 搜索引擎
time_range="month", # 时间范围
safe_search=1, # 安全搜索级别
results_format="json" # 结果格式
)
```
## 📊 规范兼容
本包遵循 [Simen Capacity Package 脚本规范 v2.1](https://github.com/capacity/specification):
- ✅ **功能导向设计**: API以业务功能为核心
- ✅ **统一返回格式**: 标准的成功/失败响应
- ✅ **完整错误处理**: 网络、HTTP、验证异常全覆盖
- ✅ **自动重试机制**: tenacity实现的指数退避重试
- ✅ **AI友好接口**: 清晰的函数签名和文档
## 📝 许可证
MIT License
Raw data
{
"_id": null,
"home_page": null,
"name": "capacity-web",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "api, capacity, http, network, scraping, search, simen, web-search",
"author": null,
"author_email": "simen <hi@simen.ai>",
"download_url": "https://files.pythonhosted.org/packages/63/ed/84c58ef0226424e7041e0f8b0d3029e29e5c3fe6fa26044649695a297808/capacity_web-1.0.5.tar.gz",
"platform": null,
"description": "# Capacity Web Search\n\n\u7f51\u7edc\u641c\u7d22\u529f\u80fd\u5305\uff0c\u63d0\u4f9b\u7b80\u5355\u6613\u7528\u7684\u7f51\u7edc\u641c\u7d22\u63a5\u53e3\u3002\n\n## \ud83d\ude80 \u5feb\u901f\u5f00\u59cb\n\n### \u5b89\u88c5\n```bash\npip install capacity-web\n```\n\n### \u4f7f\u7528\n```python\nfrom capacity_web import search_web\n\n# \u57fa\u7840\u641c\u7d22\nresult = search_web(\"\u4eba\u5de5\u667a\u80fd\u6700\u65b0\u53d1\u5c55\")\nif result[\"success\"]:\n print(f\"\u627e\u5230 {result['data']['number_of_results']} \u6761\u7ed3\u679c\")\n for item in result[\"data\"][\"results\"]:\n print(f\"\u6807\u9898: {item['title']}\")\n print(f\"\u94fe\u63a5: {item['url']}\")\n print(f\"\u6458\u8981: {item['content'][:100]}...\")\n print(f\"\u8bc4\u5206: {item['score']}\")\n print(\"---\")\n\n# \u9ad8\u7ea7\u641c\u7d22\nresult = search_web(\n \"Python\u6559\u7a0b\",\n language=\"zh\",\n max_results=10,\n categories=[\"general\"],\n time_range=\"year\"\n)\n```\n\n## \ud83d\udccb API \u6587\u6863\n\n### search_web(query, language=\"all\", max_results=None, **kwargs)\n\n\u8fdb\u884c\u7f51\u7edc\u641c\u7d22\u3002\n\n**\u53c2\u6570:**\n- `query` (str): \u641c\u7d22\u5173\u952e\u8bcd\uff0c\u5fc5\u586b\n- `language` (str): \u8bed\u8a00\u4ee3\u7801\uff0c\u9ed8\u8ba4 \"all\"\n- `max_results` (int): \u6700\u5927\u7ed3\u679c\u6570\u91cf\uff0c1-100\u4e4b\u95f4\n- `**kwargs`: \u9ad8\u7ea7\u9009\u9879\n\n**\u8fd4\u56de:**\n```python\n{\n \"success\": bool, # \u662f\u5426\u6210\u529f\n \"data\": { # \u641c\u7d22\u7ed3\u679c\u6570\u636e\n \"query\": str, # \u67e5\u8be2\u8bcd\n \"number_of_results\": int, # \u7ed3\u679c\u6570\u91cf\n \"results\": [ # \u641c\u7d22\u7ed3\u679c\u5217\u8868\n {\n \"url\": str, # \u7f51\u9875\u94fe\u63a5\n \"title\": str, # \u7f51\u9875\u6807\u9898\n \"content\": str, # \u5185\u5bb9\u6458\u8981\n \"engine\": str, # \u641c\u7d22\u5f15\u64ce\n \"score\": float, # \u76f8\u5173\u6027\u8bc4\u5206\n \"category\": str, # \u7ed3\u679c\u7c7b\u522b\n # ...\u66f4\u591a\u5b57\u6bb5\n }\n ],\n \"answers\": list, # \u76f4\u63a5\u7b54\u6848\n \"suggestions\": list, # \u641c\u7d22\u5efa\u8bae\n \"corrections\": list, # \u67e5\u8be2\u7ea0\u6b63\n \"infoboxes\": list, # \u4fe1\u606f\u6846\n \"unresponsive_engines\": list # \u65e0\u54cd\u5e94\u5f15\u64ce\n },\n \"message\": str # \u72b6\u6001\u4fe1\u606f\n}\n```\n\n## \u2728 \u7279\u6027\n\n- **\u7edf\u4e00\u8fd4\u56de\u683c\u5f0f**: \u6240\u6709API\u90fd\u8fd4\u56de `{\"success\": bool, \"data\": dict, \"message\": str}` \u683c\u5f0f\n- **\u81ea\u52a8\u91cd\u8bd5**: \u7f51\u7edc\u5f02\u5e38\u65f6\u81ea\u52a8\u91cd\u8bd5\uff0c\u6700\u591a3\u6b21\uff0c\u6307\u6570\u9000\u907f\n- **\u5b8c\u6574\u9519\u8bef\u5904\u7406**: \u6355\u83b7\u6240\u6709\u7f51\u7edc\u3001HTTP\u3001\u9a8c\u8bc1\u9519\u8bef\n- **AI\u53cb\u597d**: \u7b80\u6d01\u7684API\u8bbe\u8ba1\uff0c\u6613\u4e8e\u7406\u89e3\u548c\u4f7f\u7528\n- **\u7c7b\u578b\u63d0\u793a**: \u5b8c\u6574\u7684\u7c7b\u578b\u6ce8\u89e3\u652f\u6301\n\n## \ud83d\udd27 \u9ad8\u7ea7\u9009\u9879\n\n```python\nresult = search_web(\n \"\u641c\u7d22\u8bcd\",\n language=\"zh\", # \u8bed\u8a00: \"zh\", \"en\", \"all\" \u7b49\n max_results=20, # \u6700\u5927\u7ed3\u679c\u6570\n page_number=1, # \u9875\u7801\n categories=[\"general\", \"news\"], # \u641c\u7d22\u7c7b\u522b\n search_engines=[\"google\", \"bing\"], # \u641c\u7d22\u5f15\u64ce\n time_range=\"month\", # \u65f6\u95f4\u8303\u56f4\n safe_search=1, # \u5b89\u5168\u641c\u7d22\u7ea7\u522b\n results_format=\"json\" # \u7ed3\u679c\u683c\u5f0f\n)\n```\n\n## \ud83d\udcca \u89c4\u8303\u517c\u5bb9\n\n\u672c\u5305\u9075\u5faa [Simen Capacity Package \u811a\u672c\u89c4\u8303 v2.1](https://github.com/capacity/specification)\uff1a\n\n- \u2705 **\u529f\u80fd\u5bfc\u5411\u8bbe\u8ba1**: API\u4ee5\u4e1a\u52a1\u529f\u80fd\u4e3a\u6838\u5fc3\n- \u2705 **\u7edf\u4e00\u8fd4\u56de\u683c\u5f0f**: \u6807\u51c6\u7684\u6210\u529f/\u5931\u8d25\u54cd\u5e94\n- \u2705 **\u5b8c\u6574\u9519\u8bef\u5904\u7406**: \u7f51\u7edc\u3001HTTP\u3001\u9a8c\u8bc1\u5f02\u5e38\u5168\u8986\u76d6\n- \u2705 **\u81ea\u52a8\u91cd\u8bd5\u673a\u5236**: tenacity\u5b9e\u73b0\u7684\u6307\u6570\u9000\u907f\u91cd\u8bd5\n- \u2705 **AI\u53cb\u597d\u63a5\u53e3**: \u6e05\u6670\u7684\u51fd\u6570\u7b7e\u540d\u548c\u6587\u6863\n\n## \ud83d\udcdd \u8bb8\u53ef\u8bc1\n\nMIT License\n",
"bugtrack_url": null,
"license": null,
"summary": "\u7f51\u7edc\u641c\u7d22\u529f\u80fd\u5305\uff0c\u63d0\u4f9b\u7b80\u5355\u6613\u7528\u7684\u7f51\u7edc\u641c\u7d22\u63a5\u53e3",
"version": "1.0.5",
"project_urls": {
"Homepage": "https://github.com/capacity/capacity-web",
"Issues": "https://github.com/capacity/capacity-web/issues",
"Repository": "https://github.com/capacity/capacity-web.git"
},
"split_keywords": [
"api",
" capacity",
" http",
" network",
" scraping",
" search",
" simen",
" web-search"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "b7a372cb12fafe381f6afc424d6ab58c2ea8955bb77c3d91ea507c7ffb280cb7",
"md5": "bc6d66aa678150b7de341a9a7e6b3889",
"sha256": "eee52dab330c2f7183b9fc1cb67d591b3aaa0d7f8dbffa85639ac4d7308164cb"
},
"downloads": -1,
"filename": "capacity_web-1.0.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bc6d66aa678150b7de341a9a7e6b3889",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 5316,
"upload_time": "2025-09-03T00:48:36",
"upload_time_iso_8601": "2025-09-03T00:48:36.722776Z",
"url": "https://files.pythonhosted.org/packages/b7/a3/72cb12fafe381f6afc424d6ab58c2ea8955bb77c3d91ea507c7ffb280cb7/capacity_web-1.0.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "63ed84c58ef0226424e7041e0f8b0d3029e29e5c3fe6fa26044649695a297808",
"md5": "3d855b347d3a03eaae2e623b9a1a7912",
"sha256": "cdb1c7f9cc84bdc8507a263dfc0ae2f200197c9cc7693758e925e716ba5d3355"
},
"downloads": -1,
"filename": "capacity_web-1.0.5.tar.gz",
"has_sig": false,
"md5_digest": "3d855b347d3a03eaae2e623b9a1a7912",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 24487,
"upload_time": "2025-09-03T00:48:38",
"upload_time_iso_8601": "2025-09-03T00:48:38.306743Z",
"url": "https://files.pythonhosted.org/packages/63/ed/84c58ef0226424e7041e0f8b0d3029e29e5c3fe6fa26044649695a297808/capacity_web-1.0.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-03 00:48:38",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "capacity",
"github_project": "capacity-web",
"github_not_found": true,
"lcname": "capacity-web"
}