)亦可命中
Source:
Example
import extractDivContent from './src/extractDivContent.mjs'
console.log(extractDivContent('<div class="ct">a<div>b</div>c</div>', 'ct'))
// => 'a<div>b</div>c'
console.log(extractDivContent('<div class="other">a</div>', 'ct'))
// => null
Parameters:
| Name |
Type |
Description |
html |
String
|
輸入HTML字串 |
className |
String
|
輸入div之class屬性字串 |
Returns:
回傳div內容字串,找不到起始標籤或標籤未閉合時回傳null
-
Type
-
String
|
null
- Description:
- Source:
Parameters:
| Name |
Type |
Description |
html |
String
|
輸入HTML字串 |
Returns:
-
Type
-
String
|
null
- Description:
- Source:
Parameters:
| Name |
Type |
Description |
html |
String
|
輸入HTML字串 |
Returns:
回傳發布時間字串,格式為'YYYY-MM-DD HH:mm:ss',無發布時間時回傳null
-
Type
-
String
|
null
- Description:
- Source:
Parameters:
| Name |
Type |
Description |
html |
String
|
輸入HTML字串 |
Returns:
-
Type
-
String
|
null
(async) fetchAiNewsAggregator(optopt) → {Promise}
- Description:
- Source:
Example
import fetchAiNewsAggregator from './src/fetchAiNewsAggregator.mjs'
let test = async () => {
let rs = await fetchAiNewsAggregator()
console.log(rs.length, rs[0])
// => 120 { url: 'https://...', time: '2026-08-07 09:02:03', title: '...', description: '', from: 'Hacker News' }
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
url |
String
|
<optional>
|
'https://raw.githubusercontent.com/SuYxh/ai-news-aggregator/refs/heads/main/data/latest-24h.json'
|
輸入來源網址字串,供測試或改指向鏡像時覆寫 |
timeout |
Integer
|
<optional>
|
30000
|
輸入單次請求逾時毫秒整數,預設30000 |
maxRetries |
Integer
|
<optional>
|
5
|
輸入最大重試次數整數,含初始共執行maxRetries+1次,預設5 |
baseDelayMs |
Integer
|
<optional>
|
3000
|
輸入重試之線性退避基礎毫秒整數,預設3000 |
maxDelayMs |
Integer
|
<optional>
|
15000
|
輸入重試之線性退避上限毫秒整數,預設15000 |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示重試訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳新聞物件陣列,各物件為{url,time,title,description,from},抓取失敗時reject回傳錯誤物件
-
Type
-
Promise
(async) fetchAllListPages(slug, cfg) → {Promise}
- Description:
- Source:
Parameters:
| Name |
Type |
Description |
slug |
String
|
輸入欄目或作者之slug字串 |
cfg |
Object
|
輸入已正規化之設定物件 |
Returns:
回傳Promise,resolve回傳{items,pages_fetched}
-
Type
-
Promise
(async) fetchAllSearchPages(buildUrl, parser, cfg) → {Promise}
- Description:
- Source:
Parameters:
| Name |
Type |
Description |
buildUrl |
function
|
輸入回傳指定頁碼網址之函數 |
parser |
function
|
輸入解析單頁HTML為項目陣列之函數 |
cfg |
Object
|
輸入已正規化之設定物件 |
Returns:
回傳Promise,resolve回傳{items,total_pages,pages_fetched}
-
Type
-
Promise
(async) fetchArticle(optopt) → {Promise}
- Description:
- Source:
Example
import { fetchArticle } from './src/fetchAisixiang.mjs'
let test = async () => {
let r = await fetchArticle({ aid: '146669' })
console.log(r.status, r.title, r.chars)
// => 'success' '葛兆光:禅宗与中国文化' 12345
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
aid |
String
|
<optional>
|
|
輸入文章aid字串,與url擇一必填 |
url |
String
|
<optional>
|
|
輸入文章網址字串,與aid擇一必填 |
baseUrl |
String
|
<optional>
|
'https://www.aisixiang.com'
|
輸入網站根網址字串,供測試或改指向鏡像時覆寫 |
timeout |
Integer
|
<optional>
|
30000
|
輸入單次請求逾時毫秒整數,預設30000 |
maxRetries |
Integer
|
<optional>
|
5
|
輸入最大重試次數整數,預設5 |
pageDelayMs |
Integer
|
<optional>
|
1000
|
輸入翻頁之頁間延遲毫秒整數,預設1000 |
maxPages |
Integer
|
<optional>
|
50
|
輸入翻頁上限正整數,上限為50,預設50 |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示過程訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳結果物件{status,site,mode,url,title,chars,markdown},aid與url皆未給或解析失敗時reject回傳錯誤物件
-
Type
-
Promise
(async) fetchArticle(optopt) → {Promise}
- Description:
- Source:
Example
import { fetchArticle } from './src/fetchGuancha.mjs'
let test = async () => {
let r = await fetchArticle({ url: 'https://www.guancha.cn/internation/2026_04_29_815417.shtml' })
console.log(r.status, r.title, r.chars)
// => 'success' 'OPEC+宣布增產' 2345
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
url |
String
|
|
|
輸入文章網址字串 |
baseUrl |
String
|
<optional>
|
'https://www.guancha.cn'
|
輸入網站根網址字串,供測試或改指向鏡像時覆寫 |
maxRetries |
Integer
|
<optional>
|
5
|
輸入最大重試次數整數,預設5 |
pageDelayMs |
Integer
|
<optional>
|
1000
|
輸入翻頁之頁間延遲毫秒整數,預設1000 |
maxPages |
Integer
|
<optional>
|
50
|
輸入翻頁上限正整數,上限為50,預設50 |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示過程訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳結果物件{status,site,mode,url,title,author,published,chars,markdown},url非有效字串時reject回傳錯誤物件
-
Type
-
Promise
(async) fetchAuthorArticles(optopt) → {Promise}
- Description:
抓取愛思想指定作者之文章清單
給name時先抓站方作者清單解析出slug再抓專欄頁(兩跳), 給slug則直接抓專欄頁;
查無此作者或該欄頁0篇時仍回status為'success'且count為0, 並以message說明, 以與抓取失敗區分
- Source:
Example
import { fetchAuthorArticles } from './src/fetchAisixiang.mjs'
let test = async () => {
let r = await fetchAuthorArticles({ name: '葛兆光' })
console.log(r.status, r.count, r.resolved.slug)
// => 'success' 123 'gezhaoguang'
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
name |
String
|
<optional>
|
|
輸入作者中文名字串,與slug擇一必填 |
slug |
String
|
<optional>
|
|
輸入作者slug字串,與name擇一必填 |
baseUrl |
String
|
<optional>
|
'https://www.aisixiang.com'
|
輸入網站根網址字串,供測試或改指向鏡像時覆寫 |
timeout |
Integer
|
<optional>
|
30000
|
輸入單次請求逾時毫秒整數,預設30000 |
maxRetries |
Integer
|
<optional>
|
5
|
輸入最大重試次數整數,預設5 |
pageDelayMs |
Integer
|
<optional>
|
1000
|
輸入翻頁之頁間延遲毫秒整數,預設1000 |
maxPages |
Integer
|
<optional>
|
50
|
輸入翻頁上限正整數,上限為50,預設50 |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示過程訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳結果物件{status,site,mode,query,resolved,fetched_at,count,items},name與slug皆未給時reject回傳錯誤物件
-
Type
-
Promise
(async) fetchAuthorArticles(optopt) → {Promise}
- Description:
- Source:
Example
import { fetchAuthorArticles } from './src/fetchGuancha.mjs'
let test = async () => {
let r = await fetchAuthorArticles({ name: '安生' })
console.log(r.status, r.count, r.resolved.slug)
// => 'success' 120 'AnSheng'
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
name |
String
|
<optional>
|
|
輸入作者中文名字串,與slug擇一必填 |
slug |
String
|
<optional>
|
|
輸入作者slug字串,與name擇一必填 |
baseUrl |
String
|
<optional>
|
'https://www.guancha.cn'
|
輸入網站根網址字串,供測試或改指向鏡像時覆寫 |
maxRetries |
Integer
|
<optional>
|
5
|
輸入最大重試次數整數,預設5 |
pageDelayMs |
Integer
|
<optional>
|
1000
|
輸入翻頁之頁間延遲毫秒整數,預設1000 |
maxPages |
Integer
|
<optional>
|
50
|
輸入翻頁上限正整數,上限為50,預設50 |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示過程訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳結果物件{status,site,mode,query,resolved,fetched_at,count,items},name與slug皆未給時reject回傳錯誤物件
-
Type
-
Promise
(async) fetchAuthorsList(optopt) → {Promise}
- Description:
- Source:
Example
import { fetchAuthorsList } from './src/fetchAisixiang.mjs'
let test = async () => {
let rs = await fetchAuthorsList()
console.log(rs.length, rs[0])
// => 963 { slug: 'gezhaoguang', name: '葛兆光' }
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
baseUrl |
String
|
<optional>
|
'https://www.aisixiang.com'
|
輸入網站根網址字串,供測試或改指向鏡像時覆寫 |
timeout |
Integer
|
<optional>
|
30000
|
輸入單次請求逾時毫秒整數,預設30000 |
maxRetries |
Integer
|
<optional>
|
5
|
輸入最大重試次數整數,預設5 |
pageDelayMs |
Integer
|
<optional>
|
1000
|
輸入翻頁之頁間延遲毫秒整數,預設1000 |
maxPages |
Integer
|
<optional>
|
50
|
輸入翻頁上限正整數,上限為50,預設50 |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示過程訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳作者物件陣列,各物件為{slug,name}
-
Type
-
Promise
(async) fetchAuthorsList(optopt) → {Promise}
- Description:
- Source:
Example
import { fetchAuthorsList } from './src/fetchGuancha.mjs'
let test = async () => {
let rs = await fetchAuthorsList()
console.log(rs.length, rs[0])
// => 636 { slug: 'AnSheng', name: '安生', letter: 'A' }
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
baseUrl |
String
|
<optional>
|
'https://www.guancha.cn'
|
輸入網站根網址字串,供測試或改指向鏡像時覆寫 |
maxRetries |
Integer
|
<optional>
|
5
|
輸入最大重試次數整數,預設5 |
pageDelayMs |
Integer
|
<optional>
|
1000
|
輸入翻頁之頁間延遲毫秒整數,預設1000 |
maxPages |
Integer
|
<optional>
|
50
|
輸入翻頁上限正整數,上限為50,預設50 |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示過程訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳作者物件陣列,各物件為{slug,name,letter}
-
Type
-
Promise
(async) fetchCnyes(optopt) → {Promise}
- Description:
抓取鉅亨網台股新聞
逐頁抓取鉅亨網tw_stock分類新聞直至達到targetTotal或無更多資料, 頁間預設間隔500毫秒以降低限流風險;
時間欄位一律轉為UTC+8之'YYYY-MM-DD HH:mm:ss'字串, 單筆publishAt缺漏或異常時該筆time退回空字串並記錄, 不影響其餘新聞
- Source:
Example
import fetchCnyes from './src/fetchCnyes.mjs'
let test = async () => {
let rs = await fetchCnyes({ targetTotal: 30 })
console.log(rs.length, rs[0])
// => 30 { time: '2026-08-07 09:02:03', title: '...', link: 'https://news.cnyes.com/news/id/1234567' }
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
url |
String
|
<optional>
|
'https://api.cnyes.com/media/api/v1/newslist/category/tw_stock'
|
輸入新聞列表API網址字串,供測試或改指向鏡像時覆寫 |
targetTotal |
Integer
|
<optional>
|
100
|
輸入目標新聞則數正整數,預設100 |
pageLimit |
Integer
|
<optional>
|
30
|
輸入單頁請求則數正整數,預設30 |
daysBack |
Integer
|
<optional>
|
10
|
輸入回溯天數正整數,預設10 |
pageDelayMs |
Integer
|
<optional>
|
500
|
輸入頁間延遲毫秒整數,預設500 |
timeout |
Integer
|
<optional>
|
30000
|
輸入單次請求逾時毫秒整數,預設30000 |
maxRetries |
Integer
|
<optional>
|
10
|
輸入最大重試次數整數,含初始共執行maxRetries+1次,預設10 |
baseDelayMs |
Integer
|
<optional>
|
5000
|
輸入重試之線性退避基礎毫秒整數,預設5000 |
maxDelayMs |
Integer
|
<optional>
|
30000
|
輸入重試之線性退避上限毫秒整數,預設30000 |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示過程訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳新聞物件陣列,各物件為{time,title,link},抓取失敗時reject回傳錯誤物件
-
Type
-
Promise
(async) fetchFuturesData(dateSlash, cfg) → {Promise}
- Description:
- Source:
Parameters:
| Name |
Type |
Description |
dateSlash |
String
|
輸入日期YYYY/MM/DD字串 |
cfg |
Object
|
輸入已正規化之設定物件 |
Returns:
回傳Promise,resolve回傳近月合約行情物件
-
Type
-
Promise
(async) fetchHackerNews(limitopt, optopt) → {Promise}
- Description:
抓取Hacker News最新文章
先取newstories.json之ID清單, 再分批(每批10筆)取各篇詳情並轉為統一格式;
分批採Promise.allSettled, 單篇重試耗盡不會拖垮同批其他已成功文章;
僅保留type為story者, 無外部連結時以Hacker News站內討論頁網址替代
- Source:
Example
import fetchHackerNews from './src/fetchHackerNews.mjs'
let test = async () => {
let rs = await fetchHackerNews(5)
console.log(rs.length, rs[0])
// => 5 { url: 'https://...', time: '2026-08-07 09:02:03', title: '...', description: '', from: 'Hacker News' }
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
limit |
Integer
|
<optional>
|
30
|
輸入取回文章數量正整數,非正整數時改用預設值,預設30 |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
apiBase |
String
|
<optional>
|
'https://hacker-news.firebaseio.com/v0'
|
輸入API根網址字串,供測試或改指向鏡像時覆寫 |
timeout |
Integer
|
<optional>
|
30000
|
輸入單次請求逾時毫秒整數,預設30000 |
maxRetries |
Integer
|
<optional>
|
5
|
輸入最大重試次數整數,含初始共執行maxRetries+1次,預設5 |
baseDelayMs |
Integer
|
<optional>
|
3000
|
輸入重試之線性退避基礎毫秒整數,預設3000 |
maxDelayMs |
Integer
|
<optional>
|
15000
|
輸入重試之線性退避上限毫秒整數,預設15000 |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示重試訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳文章物件陣列,各物件為{url,time,title,description,from},抓取ID清單失敗時reject回傳錯誤物件
-
Type
-
Promise
(async) fetchHtml(url, cfg) → {Promise}
- Description:
- Source:
Parameters:
| Name |
Type |
Description |
url |
String
|
輸入待抓取網址字串 |
cfg |
Object
|
輸入已正規化之設定物件 |
Returns:
回傳Promise,resolve回傳原始HTML字串
-
Type
-
Promise
(async) fetchInstitutionalData(dateSlash, cfg) → {Promise}
- Description:
- Source:
Parameters:
| Name |
Type |
Description |
dateSlash |
String
|
輸入日期YYYY/MM/DD字串 |
cfg |
Object
|
輸入已正規化之設定物件 |
Returns:
回傳Promise,resolve回傳以foreign、trust、dealers為key之未平倉物件
-
Type
-
Promise
(async) fetchKeywordArticles(keyword, optopt) → {Promise}
- Description:
- Source:
Example
import { fetchKeywordArticles } from './src/fetchAisixiang.mjs'
let test = async () => {
let r = await fetchKeywordArticles('老庄')
console.log(r.status, r.count)
// => 'success' 42
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
keyword |
String
|
|
|
輸入關鍵字字串 |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
baseUrl |
String
|
<optional>
|
'https://www.aisixiang.com'
|
輸入網站根網址字串,供測試或改指向鏡像時覆寫 |
timeout |
Integer
|
<optional>
|
30000
|
輸入單次請求逾時毫秒整數,預設30000 |
maxRetries |
Integer
|
<optional>
|
5
|
輸入最大重試次數整數,預設5 |
pageDelayMs |
Integer
|
<optional>
|
1000
|
輸入翻頁之頁間延遲毫秒整數,預設1000 |
maxPages |
Integer
|
<optional>
|
50
|
輸入翻頁上限正整數,上限為50,預設50 |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示過程訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳結果物件{status,site,mode,query,resolved,fetched_at,count,items},keyword非有效字串時reject回傳錯誤物件
-
Type
-
Promise
(async) fetchKeywordArticles(keyword, optopt) → {Promise}
- Description:
抓取觀察者網指定關鍵字之文章清單
站方搜尋API(s.guancha.cn/main/search-v2)由sojson.v4混淆並走MD5簽名, 純curl路徑無法支援,
故本函數一律回status為'error'且error為'unsupported-by-curl', 並於message建議改用作者或主題slug
- Source:
Example
import { fetchKeywordArticles } from './src/fetchGuancha.mjs'
let test = async () => {
let r = await fetchKeywordArticles('人工智能')
console.log(r.status, r.error)
// => 'error' 'unsupported-by-curl'
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
keyword |
String
|
|
|
輸入關鍵字字串 |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{} |
Returns:
回傳Promise,resolve回傳結果物件{status,site,mode,query,fetched_at,error,message},keyword非有效字串時reject回傳錯誤物件
-
Type
-
Promise
(async) fetchMoneydj(optopt) → {Promise}
- Description:
- Source:
Example
import fetchMoneydj from './src/fetchMoneydj.mjs'
let test = async () => {
let rs = await fetchMoneydj({ totalPages: 2 })
console.log(rs.length, rs[0])
// => 60 { time: '08/07 09:02', title: '...', link: 'https://www.moneydj.com/kmdj/news/...' }
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
baseUrl |
String
|
<optional>
|
'https://www.moneydj.com/kmdj/news/newsreallist.aspx?a=mb06&index1='
|
輸入列表頁網址前綴字串,頁碼會直接串接於後,供測試或改指向鏡像時覆寫 |
totalPages |
Integer
|
<optional>
|
50
|
輸入要抓取的頁數正整數,預設50 |
timeout |
Integer
|
<optional>
|
30000
|
輸入單次請求逾時毫秒整數,預設30000 |
maxRetries |
Integer
|
<optional>
|
10
|
輸入每頁最大重試次數整數,含初始共執行maxRetries+1次,預設10 |
baseDelayMs |
Integer
|
<optional>
|
5000
|
輸入重試基礎延遲毫秒整數,預設5000 |
maxDelayMs |
Integer
|
<optional>
|
30000
|
輸入重試最大延遲毫秒整數,預設30000 |
pageDelayMs |
Integer
|
<optional>
|
|
輸入頁間延遲毫秒整數,未給時採隨機1000至3000毫秒 |
onPageDone |
function
|
<optional>
|
|
輸入每頁完成時之回呼函數,傳入(pageIndex,itemCount,totalPages) |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示過程訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳新聞物件陣列,各物件為{time,title,link},抓取到0筆時reject回傳錯誤物件
-
Type
-
Promise
(async) fetchMops(optopt) → {Promise}
- Description:
抓取公開資訊觀測站(MOPS)今日重大訊息
經w-playwright啟動本機Chrome(channel為'chrome', 須已安裝Google Chrome, 可由環境變數CHROME_PATH指定執行檔)開啟MOPS重大訊息頁,
再於頁面context內逐一查詢上市、上櫃、興櫃與公開發行之今日重大訊息;
單一市場別失敗時記錄於該筆之error並續抓其餘市場別, 由hasError告知是否有失敗;
啟動瀏覽器一律加入w-playwright之守門參數(停用Chromium功能AutofillAiWalletPrivatePasses), 避免Windows上每啟動一次Chrome即替目前使用者記一次錯誤密碼而鎖定帳號
- Source:
Example
import fetchMops from './src/fetchMops.mjs'
let test = async () => {
let r = await fetchMops()
console.log(r.hasError, r.results.length, r.results[0].market)
// => false 4 '上市'
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
pageUrl |
String
|
<optional>
|
'https://mops.twse.com.tw/mops/#/web/t146sb10'
|
輸入MOPS重大訊息頁網址字串,供測試或改指向鏡像時覆寫 |
apiUrl |
String
|
<optional>
|
'https://mops.twse.com.tw/mops/api/t146sb10'
|
輸入MOPS查詢API網址字串,供測試或改指向鏡像時覆寫 |
maxRetries |
Integer
|
<optional>
|
10
|
輸入最大重試次數整數,含初始共執行maxRetries+1次,預設10;啟動瀏覽器之重試次數另以2為上限(即最多啟動3次),且僅啟動失敗或逾時才重試 |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示過程訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳結果物件{results,hasError},results各筆為{market,marketKind,data,error,timestamp},瀏覽器啟動失敗時reject回傳錯誤物件,其code為w-playwright之錯誤碼(如E_LAUNCH、E_LOGON_GUARD)
-
Type
-
Promise
(async) fetchOnce(url, cfg) → {Promise}
- Description:
- Source:
Parameters:
| Name |
Type |
Description |
url |
String
|
輸入待抓取網址字串 |
cfg |
Object
|
輸入已正規化之設定物件 |
Returns:
-
Type
-
Promise
(async) fetchPCRatio(dateSlash, cfg) → {Promise}
- Description:
- Source:
Parameters:
| Name |
Type |
Description |
dateSlash |
String
|
輸入日期YYYY/MM/DD字串 |
cfg |
Object
|
輸入已正規化之設定物件 |
Returns:
回傳Promise,resolve回傳Put/Call Ratio物件
-
Type
-
Promise
- Description:
抓取RSS訂閱源
支援RSS與Atom, 並轉為統一格式, 時間欄位一律轉為UTC+8之'YYYY-MM-DD HH:mm:ss'字串;
因YouTube等站台之RSS會回傳暫時性404, 故404亦納入重試範圍(僅fetch模式)。
部分站台(如以TLS指紋阻擋非瀏覽器用戶端者)對node內建fetch回403、對curl回200,
此時可指定opt.method為'curl'改走系統curl, 或'auto'先curl失敗再退回fetch;
curl模式需系統PATH內有curl, 且重試退避由w-fetch-web內建(3至15秒線性),
opt之baseDelayMs、maxDelayMs與retryStatus於curl模式不生效, 極短之feed(小於100字元)會被curl模式判為empty-response
- Source:
Example
import fetchRSS from './src/fetchRSS.mjs'
let test = async () => {
let rs = await fetchRSS('https://www.ptt.cc/atom/Gossiping.xml')
console.log(rs.length, rs[0])
// => 20 { url: 'https://...', time: '2026-08-07 09:02:03', title: '...', description: '...', from: '...' }
//擋node fetch之站台改走curl, 並取feed內嵌全文
let rs2 = await fetchRSS('https://alphaarchitect.com/feed', { method: 'curl', withContent: true })
console.log(rs2.length, rs2[0].content.length)
// => 5 2093
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
rssUrl |
String
|
|
|
輸入RSS網址字串,須為http或https |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
method |
String
|
<optional>
|
'fetch'
|
輸入抓取方式字串,可為'fetch'(node內建fetch)、'curl'(系統curl)、'auto'(curl優先失敗退回fetch),預設'fetch' |
withContent |
Boolean
|
<optional>
|
false
|
輸入是否於各項目附加content欄布林值,true時依content:encoded、content、summary、description之優先序取feed內嵌全文並去除HTML標籤與實體,預設false |
timeout |
Integer
|
<optional>
|
30000
|
輸入單次請求逾時毫秒整數,預設30000 |
maxRetries |
Integer
|
<optional>
|
5
|
輸入最大重試次數整數,含初始共執行maxRetries+1次,預設5 |
baseDelayMs |
Integer
|
<optional>
|
3000
|
輸入重試之線性退避基礎毫秒整數(僅fetch模式生效),預設3000 |
maxDelayMs |
Integer
|
<optional>
|
15000
|
輸入重試之線性退避上限毫秒整數(僅fetch模式生效),預設15000 |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示重試訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳項目物件陣列,各物件為{url,time,title,description,from},withContent為true時另含content欄,網址無效或抓取失敗時reject回傳錯誤物件
-
Type
-
Promise
(async) fetchStatementdog(optopt) → {Promise}
- Description:
- Source:
Example
import fetchStatementdog from './src/fetchStatementdog.mjs'
let test = async () => {
let rs = await fetchStatementdog()
console.log(rs.length, rs[0])
// => 30 { time: '2026-08-07', title: '...', link: 'https://statementdog.com/news/...' }
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
url |
String
|
<optional>
|
'https://statementdog.com/news/latest'
|
輸入新聞頁網址字串,供測試或改指向鏡像時覆寫 |
timeout |
Integer
|
<optional>
|
30000
|
輸入單次請求逾時毫秒整數,預設30000 |
maxRetries |
Integer
|
<optional>
|
10
|
輸入最大重試次數整數,含初始共執行maxRetries+1次,預設10 |
baseDelayMs |
Integer
|
<optional>
|
5000
|
輸入重試之線性退避基礎毫秒整數,預設5000 |
maxDelayMs |
Integer
|
<optional>
|
30000
|
輸入重試之線性退避上限毫秒整數,預設30000 |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示過程訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳新聞物件陣列,各物件為{time,title,link},抓取失敗或解析到0筆時reject回傳錯誤物件
-
Type
-
Promise
(async) fetchTaifex(dateStr, optopt) → {Promise}
- Description:
- Source:
Example
import fetchTaifex from './src/fetchTaifex.mjs'
let test = async () => {
let r = await fetchTaifex('20260807')
console.log(r.date, r.futures.tx.close, r.pcRatio.ratio, r.errors)
// => '20260807' 23456 108.5 []
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
dateStr |
String
|
|
|
輸入日期YYYYMMDD字串 |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
baseUrl |
String
|
<optional>
|
'https://www.taifex.com.tw'
|
輸入期交所根網址字串,供測試或改指向鏡像時覆寫 |
timeout |
Integer
|
<optional>
|
15000
|
輸入單次請求逾時毫秒整數,預設15000 |
maxRetries |
Integer
|
<optional>
|
10
|
輸入最大重試次數整數,含初始共執行maxRetries+1次,預設10 |
baseDelayMs |
Integer
|
<optional>
|
5000
|
輸入重試之線性退避基礎毫秒整數,預設5000 |
maxDelayMs |
Integer
|
<optional>
|
30000
|
輸入重試之線性退避上限毫秒整數,預設30000 |
interRequestDelayMs |
Integer
|
<optional>
|
1000
|
輸入三支CSV之間隔毫秒整數,預設1000 |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示過程訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳結果物件{date,futures,institutional,pcRatio,errors},日期無效或三支資料全失敗時reject回傳錯誤物件
-
Type
-
Promise
(async) fetchTargetWithRetry(page, target, cfg) → {Promise}
- Description:
於瀏覽器頁面內以fetch呼叫MOPS查詢API並自動重試
需於MOPS頁面context內發送請求(同源且帶站方cookie), 故採page.evaluate而非node端直接請求;
重試條件為HTTP 5xx、403、429或網路錯誤, application-level錯誤(如MOPS code 500)屬非暫時性故不重試
- Source:
Parameters:
| Name |
Type |
Description |
page |
Object
|
輸入playwright之page物件 |
target |
Object
|
輸入目標物件,內含name、marketKind、url與payload |
cfg |
Object
|
輸入已正規化之設定物件 |
Returns:
回傳Promise,resolve回傳{json,raw}或{error,retryable}
-
Type
-
Promise
(async) fetchTitleArticles(keyword, optopt) → {Promise}
- Description:
- Source:
Example
import { fetchTitleArticles } from './src/fetchAisixiang.mjs'
let test = async () => {
let r = await fetchTitleArticles('禅宗与中国文化')
console.log(r.status, r.count)
// => 'success' 3
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
keyword |
String
|
|
|
輸入標題關鍵字字串 |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
baseUrl |
String
|
<optional>
|
'https://www.aisixiang.com'
|
輸入網站根網址字串,供測試或改指向鏡像時覆寫 |
timeout |
Integer
|
<optional>
|
30000
|
輸入單次請求逾時毫秒整數,預設30000 |
maxRetries |
Integer
|
<optional>
|
5
|
輸入最大重試次數整數,預設5 |
pageDelayMs |
Integer
|
<optional>
|
1000
|
輸入翻頁之頁間延遲毫秒整數,預設1000 |
maxPages |
Integer
|
<optional>
|
50
|
輸入翻頁上限正整數,上限為50,預設50 |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示過程訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳結果物件{status,site,mode,query,resolved,fetched_at,count,items},keyword非有效字串時reject回傳錯誤物件
-
Type
-
Promise
(async) fetchTitleArticles(keyword, optopt) → {Promise}
- Description:
- Source:
Example
import { fetchTitleArticles } from './src/fetchGuancha.mjs'
let test = async () => {
let r = await fetchTitleArticles('人工智能')
console.log(r.status, r.error)
// => 'error' 'unsupported-by-curl'
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
keyword |
String
|
|
|
輸入標題關鍵字字串 |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{} |
Returns:
回傳Promise,resolve回傳結果物件{status,site,mode,query,fetched_at,error,message},keyword非有效字串時reject回傳錯誤物件
-
Type
-
Promise
(async) fetchTopicArticles(optopt) → {Promise}
- Description:
- Source:
Example
import { fetchTopicArticles } from './src/fetchAisixiang.mjs'
let test = async () => {
let r = await fetchTopicArticles({ keyword: '大数据' })
console.log(r.status, r.count, r.resolved.id)
// => 'success' 60 '301'
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
keyword |
String
|
<optional>
|
|
輸入主題名稱字串,與id擇一必填 |
id |
String
|
<optional>
|
|
輸入主題id字串,與keyword擇一必填 |
baseUrl |
String
|
<optional>
|
'https://www.aisixiang.com'
|
輸入網站根網址字串,供測試或改指向鏡像時覆寫 |
timeout |
Integer
|
<optional>
|
30000
|
輸入單次請求逾時毫秒整數,預設30000 |
maxRetries |
Integer
|
<optional>
|
5
|
輸入最大重試次數整數,預設5 |
pageDelayMs |
Integer
|
<optional>
|
1000
|
輸入翻頁之頁間延遲毫秒整數,預設1000 |
maxPages |
Integer
|
<optional>
|
50
|
輸入翻頁上限正整數,上限為50,預設50 |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示過程訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳結果物件{status,site,mode,query,resolved,fetched_at,count,items},keyword與id皆未給時reject回傳錯誤物件
-
Type
-
Promise
(async) fetchTopicArticles(optopt) → {Promise}
- Description:
- Source:
Example
import { fetchTopicArticles } from './src/fetchGuancha.mjs'
let test = async () => {
let r = await fetchTopicArticles({ name: '财经' })
console.log(r.status, r.resolved.slug, r.count)
// => 'success' 'CaiJing' 300
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
name |
String
|
<optional>
|
|
輸入主題中文名字串,與slug擇一必填 |
slug |
String
|
<optional>
|
|
輸入主題slug字串,與name擇一必填 |
baseUrl |
String
|
<optional>
|
'https://www.guancha.cn'
|
輸入網站根網址字串,供測試或改指向鏡像時覆寫 |
maxRetries |
Integer
|
<optional>
|
5
|
輸入最大重試次數整數,預設5 |
pageDelayMs |
Integer
|
<optional>
|
1000
|
輸入翻頁之頁間延遲毫秒整數,預設1000 |
maxPages |
Integer
|
<optional>
|
50
|
輸入翻頁上限正整數,上限為50,預設50 |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示過程訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳結果物件{status,site,mode,query,resolved,fetched_at,count,items},name與slug皆未給時reject回傳錯誤物件
-
Type
-
Promise
(async) fetchTopicsList(optopt) → {Promise}
- Description:
- Source:
Example
import { fetchTopicsList } from './src/fetchAisixiang.mjs'
let test = async () => {
let rs = await fetchTopicsList()
console.log(rs.length, rs[0])
// => 803 { id: '301', name: '大数据', category: '学科' }
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
baseUrl |
String
|
<optional>
|
'https://www.aisixiang.com'
|
輸入網站根網址字串,供測試或改指向鏡像時覆寫 |
timeout |
Integer
|
<optional>
|
30000
|
輸入單次請求逾時毫秒整數,預設30000 |
maxRetries |
Integer
|
<optional>
|
5
|
輸入最大重試次數整數,預設5 |
pageDelayMs |
Integer
|
<optional>
|
1000
|
輸入翻頁之頁間延遲毫秒整數,預設1000 |
maxPages |
Integer
|
<optional>
|
50
|
輸入翻頁上限正整數,上限為50,預設50 |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示過程訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳主題物件陣列,各物件為{id,name,category}
-
Type
-
Promise
(async) fetchTpex3insti(dateStr, stockCodesopt, optopt) → {Promise}
- Description:
- Source:
Example
import fetchTpex3insti from './src/fetchTpex3insti.mjs'
let test = async () => {
let r = await fetchTpex3insti('20260807', ['6488'])
console.log(r.source, r.data.length, r.data[0]['代號'])
// => 'tpex' 1 '6488'
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
dateStr |
String
|
|
|
輸入日期YYYYMMDD字串 |
stockCodes |
Array
|
<optional>
|
|
輸入股票代號字串陣列,省略或空陣列表示全市場 |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
baseUrl |
String
|
<optional>
|
'https://www.tpex.org.tw'
|
輸入櫃買中心根網址字串,供測試或改指向鏡像時覆寫 |
timeout |
Integer
|
<optional>
|
15000
|
輸入單次請求逾時毫秒整數,預設15000 |
maxRetries |
Integer
|
<optional>
|
10
|
輸入最大重試次數整數,含初始共執行maxRetries+1次,預設10 |
baseDelayMs |
Integer
|
<optional>
|
5000
|
輸入重試之線性退避基礎毫秒整數,預設5000 |
maxDelayMs |
Integer
|
<optional>
|
30000
|
輸入重試之線性退避上限毫秒整數,預設30000 |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示過程訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳結果物件{source,date,data},日期無效、無資料或欄位結構不符時reject回傳錯誤物件
-
Type
-
Promise
(async) fetchTpexMargin(dateStr, stockCodesopt, optopt) → {Promise}
- Description:
抓取櫃買中心(TPEX)上櫃融資融券
抓取指定日之上櫃個股融資融券餘額並轉為結構化資料, 可指定股票代號陣列過濾;
選表以欄位同時含「資餘額」與「券餘額」比對, 失敗則退而取第一張有資料表, 並鎖定index6與index14兩錨點欄位驗證佈局,
不符即fail-loud, 避免固定index解析在API改版後靜默產生錯誤資料
- Source:
Example
import fetchTpexMargin from './src/fetchTpexMargin.mjs'
let test = async () => {
let r = await fetchTpexMargin('20260807', ['6488'])
console.log(r.source, r.count, r.data[0].code)
// => 'tpex_margin' 1 '6488'
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
dateStr |
String
|
|
|
輸入日期YYYYMMDD字串 |
stockCodes |
Array
|
<optional>
|
|
輸入股票代號字串陣列,省略或空陣列表示全市場 |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
baseUrl |
String
|
<optional>
|
'https://www.tpex.org.tw'
|
輸入櫃買中心根網址字串,供測試或改指向鏡像時覆寫 |
timeout |
Integer
|
<optional>
|
15000
|
輸入單次請求逾時毫秒整數,預設15000 |
maxRetries |
Integer
|
<optional>
|
10
|
輸入最大重試次數整數,含初始共執行maxRetries+1次,預設10 |
baseDelayMs |
Integer
|
<optional>
|
5000
|
輸入重試之線性退避基礎毫秒整數,預設5000 |
maxDelayMs |
Integer
|
<optional>
|
30000
|
輸入重試之線性退避上限毫秒整數,預設30000 |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示過程訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳結果物件{source,date,count,data},日期無效、無資料、欄位佈局不符或指定個股查無資料時reject回傳錯誤物件
-
Type
-
Promise
(async) fetchTpexStock(dateStr, stockCodesopt, optopt) → {Promise}
- Description:
- Source:
Example
import fetchTpexStock from './src/fetchTpexStock.mjs'
let test = async () => {
let r = await fetchTpexStock('20260807', ['6488'])
console.log(r.source, r.count)
// => 'tpex' 1
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
dateStr |
String
|
|
|
輸入日期YYYYMMDD字串 |
stockCodes |
Array
|
<optional>
|
|
輸入股票代號字串陣列,例如['6499','6610'],省略或空陣列表示全市場 |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
baseUrl |
String
|
<optional>
|
'https://www.tpex.org.tw'
|
輸入櫃買中心根網址字串,供測試或改指向鏡像時覆寫 |
timeout |
Integer
|
<optional>
|
15000
|
輸入單次請求逾時毫秒整數,預設15000 |
maxRetries |
Integer
|
<optional>
|
10
|
輸入最大重試次數整數,含初始共執行maxRetries+1次,預設10 |
baseDelayMs |
Integer
|
<optional>
|
5000
|
輸入重試之線性退避基礎毫秒整數,預設5000 |
maxDelayMs |
Integer
|
<optional>
|
30000
|
輸入重試之線性退避上限毫秒整數,預設30000 |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示過程訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳結果物件{source,date,count,data},日期無效、無資料或指定個股查無資料時reject回傳錯誤物件
-
Type
-
Promise
(async) fetchTwDataHoliday(checkDateopt, optopt) → {Promise}
- Description:
- Source:
Example
import fetchTwDataHoliday from './src/fetchTwDataHoliday.mjs'
let test = async () => {
let r = await fetchTwDataHoliday('20260101')
console.log(r.dataYear, r.totalHolidays, r.isHoliday, r.holidayName)
// => '2026' 15 true '中華民國開國紀念日'
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
checkDate |
String
|
<optional>
|
|
輸入待查詢日期YYYYMMDD字串,非合法YYYYMMDD時略過單日比對 |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
url |
String
|
<optional>
|
'https://openapi.twse.com.tw/v1/holidaySchedule/holidaySchedule'
|
輸入API網址字串,供測試或改指向鏡像時覆寫 |
timeout |
Integer
|
<optional>
|
30000
|
輸入單次請求逾時毫秒整數,預設30000 |
maxRetries |
Integer
|
<optional>
|
10
|
輸入最大重試次數整數,含初始共執行maxRetries+1次,預設10 |
baseDelayMs |
Integer
|
<optional>
|
5000
|
輸入重試之線性退避基礎毫秒整數,預設5000 |
maxDelayMs |
Integer
|
<optional>
|
30000
|
輸入重試之線性退避上限毫秒整數,預設30000 |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示重試訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳結果物件{dataYear,totalHolidays,holidays},有給checkDate時另含{checkDate,isHoliday,holidayName},API回傳非JSON或空陣列時reject回傳錯誤物件
-
Type
-
Promise
(async) fetchTwseMargin(dateStr, stockCodesopt, optopt) → {Promise}
- Description:
- Source:
Example
import fetchTwseMargin from './src/fetchTwseMargin.mjs'
let test = async () => {
let r = await fetchTwseMargin('20260807', ['2330'])
console.log(r.source, r.count, r.data[0].code, r.data[0].marginBalance)
// => 'twse_margin' 1 '2330' 12345
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
dateStr |
String
|
|
|
輸入日期YYYYMMDD字串 |
stockCodes |
Array
|
<optional>
|
|
輸入股票代號字串陣列,省略或空陣列表示全市場 |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
baseUrl |
String
|
<optional>
|
'https://www.twse.com.tw'
|
輸入證交所根網址字串,供測試或改指向鏡像時覆寫 |
timeout |
Integer
|
<optional>
|
15000
|
輸入單次請求逾時毫秒整數,預設15000 |
maxRetries |
Integer
|
<optional>
|
10
|
輸入最大重試次數整數,含初始共執行maxRetries+1次,預設10 |
baseDelayMs |
Integer
|
<optional>
|
5000
|
輸入重試之線性退避基礎毫秒整數,預設5000 |
maxDelayMs |
Integer
|
<optional>
|
30000
|
輸入重試之線性退避上限毫秒整數,預設30000 |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示過程訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳結果物件{source,date,count,data},日期無效、API錯誤或指定個股查無資料時reject回傳錯誤物件
-
Type
-
Promise
(async) fetchTwseStock(dateStr, stockCodeopt, optopt) → {Promise}
- Description:
- Source:
Example
import fetchTwseStock from './src/fetchTwseStock.mjs'
let test = async () => {
let r = await fetchTwseStock('20260807', '2330')
console.log(r.stat, r.data.length)
// => 'OK' 1
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
dateStr |
String
|
|
|
輸入日期YYYYMMDD字串 |
stockCode |
String
|
<optional>
|
|
輸入股票代號字串,例如'2330',省略或給'all'表示全市場 |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
baseUrl |
String
|
<optional>
|
'https://www.twse.com.tw'
|
輸入證交所根網址字串,供測試或改指向鏡像時覆寫 |
timeout |
Integer
|
<optional>
|
10000
|
輸入單次請求逾時毫秒整數,預設10000 |
maxRetries |
Integer
|
<optional>
|
10
|
輸入最大重試次數整數,含初始共執行maxRetries+1次,預設10 |
baseDelayMs |
Integer
|
<optional>
|
5000
|
輸入重試之線性退避基礎毫秒整數,預設5000 |
maxDelayMs |
Integer
|
<optional>
|
30000
|
輸入重試之線性退避上限毫秒整數,預設30000 |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示過程訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳證交所API原始資料物件,內含fields與data等欄位,日期無效、API回傳非OK或指定日無交易資料時reject回傳錯誤物件
-
Type
-
Promise
(async) fetchTwseT86(dateStr, stockCodesopt, optopt) → {Promise}
- Description:
- Source:
Example
import fetchTwseT86 from './src/fetchTwseT86.mjs'
let test = async () => {
let r = await fetchTwseT86('20260807', ['2330'])
console.log(r.source, r.data.length, r.data[0]['證券代號'])
// => 'twse' 1 '2330'
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
dateStr |
String
|
|
|
輸入日期YYYYMMDD字串 |
stockCodes |
Array
|
<optional>
|
|
輸入股票代號字串陣列,省略或空陣列表示全市場 |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
baseUrl |
String
|
<optional>
|
'https://www.twse.com.tw'
|
輸入證交所根網址字串,供測試或改指向鏡像時覆寫 |
timeout |
Integer
|
<optional>
|
15000
|
輸入單次請求逾時毫秒整數,預設15000 |
maxRetries |
Integer
|
<optional>
|
10
|
輸入最大重試次數整數,含初始共執行maxRetries+1次,預設10 |
baseDelayMs |
Integer
|
<optional>
|
5000
|
輸入重試之線性退避基礎毫秒整數,預設5000 |
maxDelayMs |
Integer
|
<optional>
|
30000
|
輸入重試之線性退避上限毫秒整數,預設30000 |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示過程訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳結果物件{source,date,data},日期無效或API錯誤時reject回傳錯誤物件
-
Type
-
Promise
(async) fetchWithRetry(url, optopt) → {Promise}
- Description:
- Source:
Example
import fetchWithRetry from './src/fetchWithRetry.mjs'
let test = async () => {
let r = await fetchWithRetry('https://hacker-news.firebaseio.com/v0/item/1.json')
console.log(r.type, r.by)
// => 'story' 'pg'
}
await test()
.catch((err) => {
console.log(err)
})
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
url |
String
|
|
|
輸入待抓取網址字串 |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
method |
String
|
<optional>
|
'GET'
|
輸入HTTP方法字串,預設'GET' |
headers |
Object
|
<optional>
|
{}
|
輸入額外HTTP標頭物件,未指定User-Agent時自動補預設值,預設{} |
body |
String
|
<optional>
|
null
|
輸入請求主體字串,預設null代表無主體 |
responseType |
String
|
<optional>
|
'json'
|
輸入回應解析方式字串,可為'json'、'text'、'arrayBuffer',預設'json' |
encoding |
String
|
<optional>
|
''
|
輸入responseType為'text'時之解碼字串,例如'big5',預設''代表utf-8 |
timeout |
Integer
|
<optional>
|
30000
|
輸入單次請求逾時毫秒整數,預設30000 |
maxRetries |
Integer
|
<optional>
|
10
|
輸入最大重試次數整數,含初始共執行maxRetries+1次,預設10 |
baseDelayMs |
Integer
|
<optional>
|
5000
|
輸入線性退避之基礎毫秒整數,預設5000 |
maxDelayMs |
Integer
|
<optional>
|
30000
|
輸入線性退避之上限毫秒整數,預設30000 |
retryStatus |
Array
|
<optional>
|
[]
|
輸入額外視為可重試之HTTP狀態碼陣列,例如[403],預設[] |
label |
String
|
<optional>
|
''
|
輸入重試訊息前綴字串,預設'' |
useShowLog |
Boolean
|
<optional>
|
true
|
輸入是否顯示重試訊息布林值,預設true |
|
Returns:
回傳Promise,resolve回傳解析後資料,responseType為'json'時回物件、'text'時回字串、'arrayBuffer'時回ArrayBuffer,重試耗盡或遇不可重試錯誤時reject回傳錯誤物件
-
Type
-
Promise
getCfg(optopt) → {Object}
- Description:
- Source:
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{} |
Returns:
回傳已正規化之設定物件,內含baseUrl、showLog與optFetch
-
Type
-
Object
getCfg(optopt) → {Object}
- Description:
- Source:
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{} |
Returns:
回傳已正規化之設定物件,內含baseUrl、showLog與optFetch
-
Type
-
Object
getOptFetch(optopt, dfltopt) → {Object}
- Description:
正規化抓取設定
各抓取函數之timeout、maxRetries、baseDelayMs、maxDelayMs與showLog皆可由呼叫端覆寫,
未給者取該函數之預設值, 再未給者取全域預設值;
responseType、encoding、headers、retryStatus與label屬各函數固有特性, 僅由dflt指定不開放覆寫
- Source:
Example
import getOptFetch from './src/getOptFetch.mjs'
console.log(getOptFetch({ maxRetries: 2 }, { timeout: 15000, label: 'abc' }))
// => { timeout: 15000, maxRetries: 2, baseDelayMs: 5000, maxDelayMs: 30000, useShowLog: true, label: 'abc' }
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
opt |
Object
|
<optional>
|
{}
|
輸入呼叫端設定物件,預設{} |
dflt |
Object
|
<optional>
|
{}
|
輸入各抓取函數之預設值物件,預設{} |
Returns:
回傳可直接傳入fetchWithRetry之設定物件,另含showLog供呼叫端判斷是否輸出過程訊息
-
Type
-
Object
getPayload(marketKind) → {Object}
- Description:
- Source:
Parameters:
| Name |
Type |
Description |
marketKind |
String
|
輸入市場別字串,可為'sii'、'otc'、'rotc'、'pub' |
Returns:
-
Type
-
Object
(async) getXml(rssUrl, method, cfg) → {Promise}
- Description:
- Source:
Parameters:
| Name |
Type |
Description |
rssUrl |
String
|
輸入RSS網址字串 |
method |
String
|
輸入抓取方式字串,可為'fetch'、'curl'、'auto' |
cfg |
Object
|
輸入已正規化之抓取設定物件 |
Returns:
-
Type
-
Promise
(async) getXmlByCurl(rssUrl, cfg) → {Promise}
- Description:
以curl取回XML
委派w-fetch-web之fetchWebByCurl, 失敗時拋出帶statusCode之錯誤(與fetchWithRetry之錯誤形狀一致, 供上層統一處理)。
注意: fetchWebByCurl之參數名為timeoutMs(非timeout), 且其重試退避為內建之3至15秒線性,
故opt之baseDelayMs、maxDelayMs與retryStatus於curl模式不生效
- Source:
Parameters:
| Name |
Type |
Description |
rssUrl |
String
|
輸入RSS網址字串 |
cfg |
Object
|
輸入已正規化之抓取設定物件 |
Returns:
-
Type
-
Promise
htmlToMarkdown(html, optopt) → {String}
- Description:
HTML轉Markdown
採正則式逐項轉換, 不引入DOM解析器, 適用於已切出之正文區塊;
先移除script、style與註解, 再轉換標題、粗體、斜體、換行、連結與段落, 最後清除殘留標籤並收斂空行
- Source:
Example
import htmlToMarkdown from './src/htmlToMarkdown.mjs'
console.log(htmlToMarkdown('<p>a<b>b</b></p><p>c</p>'))
// => 'a**b**\n\nc'
console.log(htmlToMarkdown('<p><img src="a.png" /></p>', { image: true }))
// => ''
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
html |
String
|
|
|
輸入HTML字串 |
opt |
Object
|
<optional>
|
{}
|
輸入設定物件,預設{}
Properties
| Name |
Type |
Attributes |
Default |
Description |
image |
Boolean
|
<optional>
|
false
|
輸入是否將img標籤轉為Markdown圖片語法布林值,預設false代表直接移除 |
|
Returns:
-
Type
-
String
isHomepageHtml(html) → {Boolean}
- Description:
偵測HTML是否為觀察者網首頁
判準為首頁底部含A-Z作者索引之
- [A-Z]
標記(真正的作者欄頁、欄目頁與主題集頁皆無此區塊),
用以識別「請求被302導向首頁」之情形
- Source:
Parameters:
| Name |
Type |
Description |
html |
String
|
輸入HTML字串 |
Returns:
-
Type
-
Boolean
isNonHolidayEntry(entry) → {Boolean}
- Description:
- Source:
Parameters:
| Name |
Type |
Description |
entry |
Object
|
輸入API回傳之單筆條目物件 |
Returns:
-
Type
-
Boolean
isRetryableError(err, retryStatus) → {Boolean}
- Description:
判斷錯誤是否值得重試
有statusCode(即HTTP層錯誤)時, 5xx與429視為暫時性, 其餘由retryStatus指定;
無statusCode(即網路層錯誤)時, 由錯誤碼、AbortError與undici暫時性錯誤判斷
- Source:
Parameters:
| Name |
Type |
Description |
err |
Error
|
輸入錯誤物件 |
retryStatus |
Array
|
輸入額外視為可重試之HTTP狀態碼陣列 |
Returns:
-
Type
-
Boolean
isYmd(dateStr) → {Boolean}
- Description:
- Source:
Example
import isYmd from './src/isYmd.mjs'
console.log(isYmd('20260807'), isYmd('20260230'), isYmd('2026-08-07'), isYmd(20260807))
// => true false false false
Parameters:
| Name |
Type |
Description |
dateStr |
String
|
輸入日期字串 |
Returns:
-
Type
-
Boolean
(async) launchBrowser(cfg) → {Promise}
- Description:
經w-playwright啟動本機Chrome並帶重試
一律經w-playwright(已加入避免Windows帳號被錯誤密碼鎖定之守門參數)啟動, 不直接使用playwright;
僅E_LAUNCH、E_LAUNCH_TIMEOUT重試, 重試次數為maxRetries與MAX_LAUNCH_RETRIES取小者;
失敗時reject回傳Error, 訊息含w-playwright之固定詞彙訊息, 並帶其code
- Source:
Parameters:
| Name |
Type |
Description |
cfg |
Object
|
輸入已正規化之設定物件,內含maxRetries、baseDelayMs、maxDelayMs與useShowLog |
Returns:
回傳Promise,resolve回傳playwright之browser物件
-
Type
-
Promise
lookupAuthor(authors, name) → {Object|null}
- Description:
- Source:
Example
import { lookupAuthor } from './src/fetchAisixiang.mjs'
console.log(lookupAuthor([{ slug: 'gezhaoguang', name: '葛兆光' }], '葛兆光'))
// => { slug: 'gezhaoguang', name: '葛兆光' }
Parameters:
| Name |
Type |
Description |
authors |
Array
|
輸入作者物件陣列 |
name |
String
|
輸入作者中文名字串 |
Returns:
-
Type
-
Object
|
null
lookupAuthor(authors, name) → {Object|null}
- Description:
- Source:
Example
import { lookupAuthor } from './src/fetchGuancha.mjs'
console.log(lookupAuthor([{ slug: 'AnSheng', name: '安生' }], '安生'))
// => { slug: 'AnSheng', name: '安生' }
Parameters:
| Name |
Type |
Description |
authors |
Array
|
輸入作者物件陣列 |
name |
String
|
輸入作者中文名字串 |
Returns:
-
Type
-
Object
|
null
lookupTopic(topics, name) → {Object|null}
- Description:
- Source:
Example
import { lookupTopic } from './src/fetchAisixiang.mjs'
console.log(lookupTopic([{ id: '301', name: '大数据' }], '大数据'))
// => { id: '301', name: '大数据' }
Parameters:
| Name |
Type |
Description |
topics |
Array
|
輸入主題物件陣列 |
name |
String
|
輸入主題名稱字串 |
Returns:
-
Type
-
Object
|
null
lookupTopic(name) → {Object|null}
- Description:
- Source:
Example
import { lookupTopic } from './src/fetchGuancha.mjs'
console.log(lookupTopic('财经'))
// => { slug: 'CaiJing', name: '财经' }
Parameters:
| Name |
Type |
Description |
name |
String
|
輸入主題名稱字串 |
Returns:
-
Type
-
Object
|
null
parseAuthorColumnPage(html, baseUrl) → {Array}
- Description:
- Source:
Parameters:
| Name |
Type |
Description |
html |
String
|
輸入作者專欄頁HTML字串 |
baseUrl |
String
|
輸入網站根網址字串 |
Returns:
回傳文章物件陣列,各物件為{aid,url,title,category}
-
Type
-
Array
parseAuthorIndex(html) → {Array}
- Description:
- Source:
Parameters:
| Name |
Type |
Description |
html |
String
|
輸入首頁HTML字串 |
Returns:
回傳作者物件陣列,各物件為{slug,name,letter}
-
Type
-
Array
parseCSV(csvText) → {Array}
- Description:
- Source:
Parameters:
| Name |
Type |
Description |
csvText |
String
|
輸入CSV文字字串 |
Returns:
-
Type
-
Array
parseCSVLine(line) → {Array}
- Description:
- Source:
Parameters:
| Name |
Type |
Description |
line |
String
|
輸入CSV單行字串 |
Returns:
-
Type
-
Array
parseIntComma(str) → {Number}
- Description:
- Source:
Example
import parseIntComma from './src/parseIntComma.mjs'
console.log(parseIntComma('1,234,567'), parseIntComma('-'), parseIntComma(''), parseIntComma(12))
// => 1234567 0 0 12
Parameters:
| Name |
Type |
Description |
str |
String
|
輸入含千分位逗號之數值字串 |
Returns:
-
Type
-
Number
parseListPage(html, baseUrl) → {Array}
- Description:
解析列表頁之文章清單
列表頁slug與文章URL slug通常不同(作者頁同slug, 主題集頁用各自作者slug, 欄目頁用大頻道slug),
故本函數不限定文章URL之slug, 抽出所有符合//<YYYY_MM_DD>_.shtml模式之連結
- Source:
Parameters:
| Name |
Type |
Description |
html |
String
|
輸入列表頁HTML字串 |
baseUrl |
String
|
輸入網站根網址字串 |
Returns:
回傳文章物件陣列,各物件為{url,title,slug}
-
Type
-
Array
parseNum(str) → {Number|null}
- Description:
- Source:
Parameters:
| Name |
Type |
Description |
str |
String
|
輸入數值字串 |
Returns:
回傳數值,為'-'、空字串或無法轉換時回傳null
-
Type
-
Number
|
null
parseSearchResults(html, baseUrl) → {Array}
- Description:
- Source:
Parameters:
| Name |
Type |
Description |
html |
String
|
輸入搜尋結果頁HTML字串 |
baseUrl |
String
|
輸入網站根網址字串 |
Returns:
回傳文章物件陣列,各物件為{aid,url,title,author}
-
Type
-
Array
parseSearchTotalPages(html) → {Integer}
- Description:
- Source:
Parameters:
| Name |
Type |
Description |
html |
String
|
輸入列表頁HTML字串 |
Returns:
-
Type
-
Integer
parseZhuantiArticles(html, baseUrl) → {Array}
- Description:
- Source:
Parameters:
| Name |
Type |
Description |
html |
String
|
輸入主題頁HTML字串 |
baseUrl |
String
|
輸入網站根網址字串 |
Returns:
回傳文章物件陣列,各物件為{aid,url,title,author}
-
Type
-
Array
pickPint(opt, dflt, key, fallback) → {Integer}
- Description:
- Source:
Parameters:
| Name |
Type |
Description |
opt |
Object
|
輸入呼叫端設定物件 |
dflt |
Object
|
輸入各抓取函數之預設值物件 |
key |
String
|
輸入設定鍵名字串 |
fallback |
Integer
|
輸入無設定時之預設整數 |
Returns:
-
Type
-
Integer
rocToWestern(rocDate) → {String}
- Description:
- Source:
Parameters:
| Name |
Type |
Description |
rocDate |
String
|
輸入民國日期字串,年份位數不限 |
Returns:
-
Type
-
String
safeFilename(name) → {String}
- Description:
- Source:
Example
import safeFilename from './src/safeFilename.mjs'
console.log(safeFilename('a/b:c*d?e'))
// => 'a_b_c_d_e'
Parameters:
| Name |
Type |
Description |
name |
String
|
輸入檔名字串 |
Returns:
-
Type
-
String
stripHtml(html) → {String}
- Description:
去除HTML標籤與實體, 保留段落換行
與htmlToMarkdown不同, 本函數輸出純文字(不產生Markdown標記), 供feed內嵌全文等
「只要內文、不要格式」之場景使用;
先移除script與style, 再將段落類閉合標籤與br轉為換行, 最後清除殘留標籤並解碼實體
- Source:
Example
import stripHtml from './src/stripHtml.mjs'
console.log(stripHtml('<p>第一段<b>粗體</b></p><p>第二段&實體</p>'))
// => '第一段粗體\n第二段&實體'
Parameters:
| Name |
Type |
Description |
html |
String
|
輸入HTML字串 |
Returns:
-
Type
-
String
toDatetimeUTC8(value) → {String}
- Description:
時間轉UTC+8之日期時間字串
可接受ISO時間字串、RFC822時間字串、純日期字串、unix秒數(Number, 非毫秒)或Date物件,
一律輸出台灣時間'YYYY-MM-DD HH:mm:ss', 且不受執行環境時區影響。
兩類輸入之時區語意不同, 故分開處理:
帶有時刻資訊者(ISO、RFC822、unix秒數、Date)代表一個絕對時點, 換算為UTC+8之當地時刻;
純日期字串本身不含時點, 直接視為UTC+8當日之00:00:00, 不因執行環境時區而位移日期
(否則在UTC+14環境下'2024'會被解為2023-12-31)。
- Source:
Example
import toDatetimeUTC8 from './src/toDatetimeUTC8.mjs'
console.log(toDatetimeUTC8('2026-08-07T01:02:03Z'))
// => '2026-08-07 09:02:03'
console.log(toDatetimeUTC8(1786000000))
// => '2026-08-06 15:06:40'
console.log(toDatetimeUTC8('2024'), toDatetimeUTC8('20260807'))
// => '2024-01-01 00:00:00' '2026-08-07 00:00:00'
console.log(toDatetimeUTC8('abc'), toDatetimeUTC8(''), toDatetimeUTC8(null))
// => '' '' ''
Parameters:
| Name |
Type |
Description |
value |
String
|
Number
|
Date
|
輸入ISO或RFC822時間字串、純日期字串、unix秒數或Date物件 |
Returns:
回傳UTC+8之日期時間字串,格式為'YYYY-MM-DD HH:mm:ss',輸入為空或無法解析時回傳''
-
Type
-
String
toRocDate(dateStr) → {String}
- Description:
- Source:
Example
import toRocDate from './src/toRocDate.mjs'
console.log(toRocDate('20260807'), toRocDate('19110101'))
// => '115/08/07' '0/01/01'
Parameters:
| Name |
Type |
Description |
dateStr |
String
|
輸入西元日期YYYYMMDD字串 |
Returns:
回傳民國日期字串,格式為'YYY/MM/DD',輸入非有效字串時回傳''
-
Type
-
String