@bgicli/bgicli 2.7.6 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,72 +2,40 @@
2
2
  id: web-search
3
3
  name: Web Search (网络搜索)
4
4
  category: utility
5
- short-description: Search the internet using DuckDuckGo API and curl/Python for any query.
5
+ short-description: Search the internet using DuckDuckGo API.
6
6
  ---
7
7
 
8
- # Web Search 网络搜索
8
+ # Web Search
9
9
 
10
- 当用户需要搜索互联网、查找最新信息、核实事实、或查询非文献数据库内容时,使用以下方法通过 bash 工具执行网络搜索。
10
+ 当用户需要搜索互联网、查找最新信息或核实事实时,直接用 bash 执行,无需询问是否搜索。
11
11
 
12
- ## 规则
13
- - 直接搜索,不要事先询问"是否需要搜索"
14
- - 搜索到内容后,整合总结后再回复,不要直接粘贴原始 JSON
15
- - 如果首次搜索结果不理想,换关键词重试一次
16
- - 中文问题优先用中文关键词;专业术语用英文效果更好
12
+ **规则**:搜索后整合总结再回复,不要粘贴原始 JSON;结果不理想时换关键词重试;中文问题优先中文关键词,专业术语用英文。
17
13
 
18
- ## 方法一:DuckDuckGo Instant Answer(无需 API Key,适合快速摘要)
14
+ ## 搜索(DuckDuckGo,无需 API Key
19
15
 
20
16
  ```bash
21
17
  python3 - <<'EOF'
22
- import urllib.request, urllib.parse, json, sys
23
-
18
+ import urllib.request, urllib.parse, json
24
19
  query = "YOUR_QUERY_HERE"
25
20
  url = "https://api.duckduckgo.com/?q=" + urllib.parse.quote(query) + "&format=json&no_html=1&skip_disambig=1"
26
- try:
27
- with urllib.request.urlopen(url, timeout=10) as r:
28
- d = json.loads(r.read())
29
- if d.get("AbstractText"):
30
- print("摘要:", d["AbstractText"])
31
- print("来源:", d.get("AbstractURL", ""))
32
- topics = [t for t in d.get("RelatedTopics", []) if isinstance(t, dict) and t.get("Text")]
33
- for t in topics[:6]:
34
- print("•", t["Text"])
35
- if t.get("FirstURL"):
36
- print(" ", t["FirstURL"])
37
- except Exception as e:
38
- print("搜索失败:", e, file=sys.stderr)
21
+ with urllib.request.urlopen(url, timeout=10) as r:
22
+ d = json.loads(r.read())
23
+ if d.get("AbstractText"): print("摘要:", d["AbstractText"], "\n来源:", d.get("AbstractURL",""))
24
+ for t in d.get("RelatedTopics", [])[:6]:
25
+ if isinstance(t, dict) and t.get("Text"): print("", t["Text"])
39
26
  EOF
40
27
  ```
41
28
 
42
- ## 方法二:获取并解析具体网页内容
29
+ ## 获取网页内容
43
30
 
44
31
  ```bash
45
32
  python3 - <<'EOF'
46
- import urllib.request, re, sys
47
-
33
+ import urllib.request, re
48
34
  url = "https://TARGET_URL_HERE"
49
- try:
50
- req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
51
- with urllib.request.urlopen(req, timeout=15) as r:
52
- html = r.read().decode("utf-8", errors="ignore")
53
- text = re.sub(r"<script[^>]*>[\s\S]*?</script>", "", html, flags=re.I)
54
- text = re.sub(r"<style[^>]*>[\s\S]*?</style>", "", text, flags=re.I)
55
- text = re.sub(r"<[^>]+>", " ", text)
56
- text = re.sub(r"\s{3,}", "\n\n", text)
57
- print(text[:4000])
58
- except Exception as e:
59
- print("获取失败:", e, file=sys.stderr)
35
+ req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
36
+ with urllib.request.urlopen(req, timeout=15) as r:
37
+ html = r.read().decode("utf-8", errors="ignore")
38
+ text = re.sub(r"<[^>]+>", " ", re.sub(r"<(script|style)[^>]*>[\s\S]*?</\1>", "", html, flags=re.I))
39
+ print(re.sub(r"\s{3,}", "\n\n", text)[:4000])
60
40
  EOF
61
41
  ```
62
-
63
- ## 方法三:curl 快速搜索
64
-
65
- ```bash
66
- curl -sA "Mozilla/5.0" "https://api.duckduckgo.com/?q=QUERY&format=json&no_html=1" \
67
- | python3 -c "
68
- import json,sys
69
- d=json.load(sys.stdin)
70
- print(d.get('AbstractText',''))
71
- [print('•',t['Text']) for t in d.get('RelatedTopics',[])[:5] if isinstance(t,dict) and t.get('Text')]
72
- "
73
- ```