Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions clis/36kr/hot.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* 36kr hot-list — INTERCEPT strategy.
* 36kr hot-list — DOM scraping.
*
* Navigates to the 36kr hot-list page and scrapes rendered article links.
* Supports category types: renqi (人气), zonghe (综合), shoucang (收藏), catalog (综合热门).
Expand Down Expand Up @@ -34,7 +34,8 @@ cli({
name: 'hot',
description: '36氪热榜 — trending articles (renqi/zonghe/shoucang/catalog)',
domain: 'www.36kr.com',
strategy: Strategy.INTERCEPT,
strategy: Strategy.PUBLIC,
browser: true,
args: [
{ name: 'limit', type: 'int', default: 20, help: 'Number of items (max 50)' },
{
Expand All @@ -58,9 +59,13 @@ cli({

const url = buildHotListUrl(listType);

await page.installInterceptor('36kr.com/api');
await page.goto(url);
await page.waitForCapture(6);
// Poll DOM until article links appear (36kr renders client-side)
const deadline = Date.now() + 5000;
while (Date.now() < deadline) {
if (await page.evaluate('document.querySelectorAll("a[href*=\\"/p/\\"]").length')) break;
await new Promise(r => setTimeout(r, 300));
}

// Scrape rendered article links from DOM (deduplicated)
const domItems: any = await page.evaluate(`
Expand Down
13 changes: 9 additions & 4 deletions clis/36kr/search.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* 36kr article search — INTERCEPT strategy.
* 36kr article search — DOM scraping.
*
* Navigates to the 36kr search results page and scrapes rendered articles.
*/
Expand All @@ -12,7 +12,8 @@ cli({
name: 'search',
description: '搜索36氪文章',
domain: 'www.36kr.com',
strategy: Strategy.INTERCEPT,
strategy: Strategy.PUBLIC,
browser: true,
args: [
{ name: 'query', positional: true, required: true, help: 'Search keyword (e.g. "AI", "OpenAI")' },
{ name: 'limit', type: 'int', default: 20, help: 'Number of results (max 50)' },
Expand All @@ -22,9 +23,13 @@ cli({
const count = Math.min(Number(args.limit) || 20, 50);
const query = encodeURIComponent(String(args.query ?? ''));

await page.installInterceptor('36kr.com/api');
await page.goto(`https://www.36kr.com/search/articles/${query}`);
await page.waitForCapture(6);
// Poll DOM until article links appear (36kr renders client-side)
const deadline = Date.now() + 5000;
while (Date.now() < deadline) {
if (await page.evaluate('document.querySelectorAll("a[href*=\\"/p/\\"]").length')) break;
await new Promise(r => setTimeout(r, 300));
}

const domItems: any = await page.evaluate(`
(() => {
Expand Down