export interface SearchResultItem { title: string; url: string; snippet: string; displayUrl?: string; } export interface ParsedSearchResults { items: SearchResultItem[]; totalResults?: string; engine: string; } export function parseBingResults(html: string, maxResults: number, snippetLength: number): ParsedSearchResults { const items: SearchResultItem[] = []; // Bing 结果项在
或
const snippetMatch = block.match(/
]*class="[^"]*b_lineclamp[^"]*"[^>]*>([\s\S]*?)<\/p>/i) || block.match(/
]*>([\s\S]*?)<\/p>/i);
const snippet = snippetMatch ? truncate(stripTags(snippetMatch[1]).trim(), snippetLength) : "";
// 显示URL
const displayMatch = block.match(/]*>([\s\S]*?)<\/cite>/i);
const displayUrl = displayMatch ? stripTags(displayMatch[1]).trim() : undefined;
items.push({ title, url, snippet, displayUrl });
}
return { items, engine: "bing" };
}
export function parseBaiduResults(html: string, maxResults: number, snippetLength: number): ParsedSearchResults {
const items: SearchResultItem[] = [];
// 百度结果项在