browser-web-search 0.3.0 → 0.3.2

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.
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  - **零配置** — 无需 Chrome Extension、无需 Daemon,开箱即用
8
8
  - **复用登录态** — 使用浏览器中的登录状态,无需 API Key
9
- - **13 个平台,41 个命令** — 覆盖搜索、社交、新闻、开发、视频、招聘等场景
9
+ - **17 个平台,37 个命令** — 覆盖搜索、社交、新闻、视频、招聘等场景
10
10
  - **AI Agent 友好** — 结构化 JSON 输出,内置 jq 过滤
11
11
 
12
12
  ## 安装
@@ -25,20 +25,24 @@ bws site zhihu/hot # 知乎热榜
25
25
  bws site bilibili/popular # B站热门视频
26
26
  ```
27
27
 
28
- ## 内置平台(13 个)
28
+ ## 内置平台(17 个)
29
29
 
30
30
  | 平台 | 说明 | 命令 |
31
31
  |-----|------|-----|
32
- | **今日头条** | 新闻资讯 | `toutiao/hot`, `toutiao/search` |
33
- | **小红书** | 生活分享 | `xiaohongshu/search`, `xiaohongshu/note`, `xiaohongshu/comments`, `xiaohongshu/user_posts` |
34
- | **36kr** | 科技创投 | `36kr/newsflash` |
32
+ | **今日头条** | 新闻资讯 | `toutiao/hot`, `toutiao/search`, `toutiao/feed` |
33
+ | **澎湃新闻** | 权威新闻 | `thepaper/hot` |
34
+ | **腾讯新闻** | 热点新闻 | `qqnews/hot` |
35
+ | **网易新闻** | 热点新闻 | `netease/hot` |
36
+ | **新浪新闻** | 门户新闻 | `sina/hot` |
37
+ | **微博** | 社交热搜 | `weibo/hot` |
38
+ | **微信公众号** | 公众号文章 | `weixin/search`, `weixin/article` |
39
+ | **小红书** | 生活分享 | `xiaohongshu/search`, `xiaohongshu/note`, `xiaohongshu/comments`, `xiaohongshu/feed`, `xiaohongshu/me`, `xiaohongshu/user_posts` |
40
+ | **36kr** | 科技创投 | `36kr/newsflash`, `36kr/search`, `36kr/article` |
35
41
  | **知乎** | 问答社区 | `zhihu/hot`, `zhihu/search`, `zhihu/question`, `zhihu/me` |
36
42
  | **CSDN** | 开发者社区 | `csdn/search` |
37
43
  | **博客园** | 技术博客 | `cnblogs/search` |
38
- | **豆瓣** | 影视书籍 | `douban/movie`, `douban/search`, `douban/top250`, `douban/movie-hot`, `douban/movie-top`, `douban/comments` |
39
44
  | **Bilibili** | 视频弹幕 | `bilibili/popular`, `bilibili/trending`, `bilibili/ranking`, `bilibili/search`, `bilibili/video`, `bilibili/comments`, `bilibili/feed`, `bilibili/history`, `bilibili/me` |
40
45
  | **BOSS直聘** | 招聘平台 | `boss/search`, `boss/detail` |
41
- | **GitHub** | 代码托管 | `github/repo`, `github/issues`, `github/fork`, `github/pr-create`, `github/issue-create` |
42
46
  | **Baidu** | 百度搜索 | `baidu/search` |
43
47
  | **Bing** | 必应搜索 | `bing/search` |
44
48
  | **Google** | 谷歌搜索 | `google/search` |
@@ -65,8 +69,8 @@ bws site xiaohongshu/search "美食" --jq '.notes[].title'
65
69
  # B站热门视频 JSON
66
70
  bws site bilibili/popular --json
67
71
 
68
- # GitHub 仓库信息
69
- bws site github/repo facebook/react
72
+ # 微博热搜
73
+ bws site weibo/hot
70
74
  ```
71
75
 
72
76
  ## 登录态
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browser-web-search",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "把任何网站变成命令行 API,专为 OpenClaw 设计,复用浏览器登录态",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,73 @@
1
+ /* @meta
2
+ {
3
+ "name": "weixin/article",
4
+ "description": "获取微信公众号文章内容",
5
+ "domain": "mp.weixin.qq.com",
6
+ "args": {},
7
+ "readOnly": true,
8
+ "example": "bws weixin/article"
9
+ }
10
+ */
11
+
12
+ async function(args) {
13
+ // 检查是否在微信公众号文章页面
14
+ if (!location.href.includes('mp.weixin.qq.com')) {
15
+ return {
16
+ error: 'Not on WeChat article page',
17
+ hint: 'First open the article: openclaw browser open <article_url>'
18
+ };
19
+ }
20
+
21
+ // 检查是否需要验证
22
+ const captchaEl = document.querySelector('.weui-msg__title');
23
+ if (captchaEl && captchaEl.textContent.includes('验证')) {
24
+ return {
25
+ error: 'Captcha required',
26
+ hint: 'Please complete the verification in the browser first'
27
+ };
28
+ }
29
+
30
+ // 提取文章信息
31
+ const titleEl = document.querySelector('#activity-name, .rich_media_title');
32
+ const authorEl = document.querySelector('#js_name, .rich_media_meta_nickname');
33
+ const contentEl = document.querySelector('#js_content, .rich_media_content');
34
+ const publishTimeEl = document.querySelector('#publish_time, .rich_media_meta_text');
35
+
36
+ if (!titleEl || !contentEl) {
37
+ return {
38
+ error: 'Failed to extract article content',
39
+ hint: 'Page structure may have changed or article not fully loaded'
40
+ };
41
+ }
42
+
43
+ // 提取正文文本
44
+ const paragraphs = [];
45
+ const sections = contentEl.querySelectorAll('p, section');
46
+ sections.forEach(el => {
47
+ const text = el.textContent?.trim();
48
+ if (text && text.length > 0) {
49
+ paragraphs.push(text);
50
+ }
51
+ });
52
+
53
+ // 提取图片
54
+ const images = [];
55
+ const imgEls = contentEl.querySelectorAll('img[data-src], img[src]');
56
+ imgEls.forEach(img => {
57
+ const src = img.getAttribute('data-src') || img.src;
58
+ if (src && !src.includes('data:image')) {
59
+ images.push(src);
60
+ }
61
+ });
62
+
63
+ return {
64
+ title: titleEl.textContent?.trim() || '',
65
+ author: authorEl?.textContent?.trim() || '',
66
+ publishTime: publishTimeEl?.textContent?.trim() || '',
67
+ url: location.href,
68
+ content: paragraphs.join('\n\n'),
69
+ paragraphCount: paragraphs.length,
70
+ imageCount: images.length,
71
+ images: images.slice(0, 10)
72
+ };
73
+ }
@@ -0,0 +1,96 @@
1
+ /* @meta
2
+ {
3
+ "name": "weixin/search",
4
+ "description": "搜索微信公众号文章 (通过搜狗微信)",
5
+ "domain": "weixin.sogou.com",
6
+ "args": {
7
+ "query": {"required": true, "description": "搜索关键词"},
8
+ "count": {"required": false, "description": "返回数量 (默认 10)"}
9
+ },
10
+ "readOnly": true,
11
+ "example": "bws weixin/search AI"
12
+ }
13
+ */
14
+
15
+ async function(args) {
16
+ const query = args.query;
17
+ if (!query) {
18
+ return {error: 'Missing query parameter'};
19
+ }
20
+ const maxCount = Math.min(parseInt(args.count) || 10, 20);
21
+
22
+ // 通过 fetch 请求搜狗微信搜索页面
23
+ const searchUrl = 'https://weixin.sogou.com/weixin?type=2&s_from=input&query=' + encodeURIComponent(query);
24
+
25
+ const resp = await fetch(searchUrl, {
26
+ credentials: 'include',
27
+ headers: {
28
+ 'Accept': 'text/html,application/xhtml+xml'
29
+ }
30
+ });
31
+
32
+ if (!resp.ok) {
33
+ return {error: 'HTTP ' + resp.status, hint: 'Open weixin.sogou.com in browser first'};
34
+ }
35
+
36
+ const html = await resp.text();
37
+
38
+ // 检查是否需要验证码
39
+ if (html.includes('请输入验证码') || html.includes('antispider')) {
40
+ return {
41
+ error: 'Captcha required',
42
+ hint: 'Please visit weixin.sogou.com in browser and complete verification first',
43
+ url: searchUrl
44
+ };
45
+ }
46
+
47
+ // 解析 HTML
48
+ const parser = new DOMParser();
49
+ const doc = parser.parseFromString(html, 'text/html');
50
+
51
+ const items = [];
52
+ const results = doc.querySelectorAll('.news-list li, ul.news-list > li');
53
+
54
+ if (results.length === 0) {
55
+ return {
56
+ error: 'No results found',
57
+ hint: 'Try different keywords or check weixin.sogou.com manually',
58
+ query: query
59
+ };
60
+ }
61
+
62
+ results.forEach((item, i) => {
63
+ if (i >= maxCount) return;
64
+
65
+ const titleEl = item.querySelector('h3 a, .txt-box h3 a');
66
+ const summaryEl = item.querySelector('p.txt-info, .txt-box p');
67
+ const sourceEl = item.querySelector('a.account, .s-p a[href*="gzh"]');
68
+ const timeEl = item.querySelector('.s-p span:last-child, span.s2');
69
+ const imgEl = item.querySelector('img');
70
+
71
+ if (titleEl) {
72
+ items.push({
73
+ rank: i + 1,
74
+ title: titleEl.textContent?.trim().replace(/\s+/g, ' ') || '',
75
+ url: titleEl.href || '',
76
+ summary: summaryEl?.textContent?.trim().replace(/\s+/g, ' ') || '',
77
+ account: sourceEl?.textContent?.trim() || '',
78
+ time: timeEl?.textContent?.trim() || '',
79
+ cover: imgEl?.src || imgEl?.getAttribute('data-src') || ''
80
+ });
81
+ }
82
+ });
83
+
84
+ if (items.length === 0) {
85
+ return {
86
+ error: 'Failed to parse results',
87
+ hint: 'Page structure may have changed'
88
+ };
89
+ }
90
+
91
+ return {
92
+ query: query,
93
+ count: items.length,
94
+ items
95
+ };
96
+ }