webpeel 0.21.72 → 0.21.73
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/dist/cli/commands/fetch.js +14 -6
- package/dist/cli/commands/search.js +96 -0
- package/dist/cli/utils.js +31 -1
- package/dist/cli.js +14 -0
- package/dist/core/search-fallback.d.ts +1 -0
- package/dist/core/search-fallback.js +43 -18
- package/package.json +2 -2
|
@@ -682,13 +682,21 @@ export async function runFetch(url, options) {
|
|
|
682
682
|
result = await fetchViaApi(url, peelOptions, fetchApiKey, fetchApiUrl);
|
|
683
683
|
}
|
|
684
684
|
else {
|
|
685
|
-
// No API key —
|
|
685
|
+
// No API key — fall back to local peel() mode (runs locally, no API needed)
|
|
686
686
|
if (spinner)
|
|
687
|
-
spinner.
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
await
|
|
691
|
-
|
|
687
|
+
spinner.text = 'Fetching locally (no API key)…';
|
|
688
|
+
const startLocal = Date.now();
|
|
689
|
+
const { peel } = await import('../../index.js');
|
|
690
|
+
const localResult = await peel(url, peelOptions);
|
|
691
|
+
const elapsed = Date.now() - startLocal;
|
|
692
|
+
// Normalize to the shape fetchViaApi returns
|
|
693
|
+
result = {
|
|
694
|
+
...localResult,
|
|
695
|
+
elapsed: localResult.elapsed ?? elapsed,
|
|
696
|
+
method: localResult.method ?? 'local',
|
|
697
|
+
tokens: localResult.tokens ?? Math.ceil((localResult.content?.length ?? 0) / 4),
|
|
698
|
+
cached: false,
|
|
699
|
+
};
|
|
692
700
|
}
|
|
693
701
|
// Update lastUsed timestamp for named profiles
|
|
694
702
|
if (resolvedProfileName) {
|
|
@@ -588,4 +588,100 @@ export function registerSearchCommands(program) {
|
|
|
588
588
|
process.exit(1);
|
|
589
589
|
}
|
|
590
590
|
});
|
|
591
|
+
// ── extractors command ────────────────────────────────────────────────────
|
|
592
|
+
program
|
|
593
|
+
.command('extractors')
|
|
594
|
+
.alias('list-extractors')
|
|
595
|
+
.description('List all supported domain extractors')
|
|
596
|
+
.option('--json', 'Output as JSON')
|
|
597
|
+
.action((options) => {
|
|
598
|
+
const extractors = [
|
|
599
|
+
// Social
|
|
600
|
+
{ domain: 'twitter.com / x.com', category: 'Social', description: 'Tweets, threads, profiles' },
|
|
601
|
+
{ domain: 'reddit.com', category: 'Social', description: 'Subreddits, posts, comments' },
|
|
602
|
+
{ domain: 'instagram.com', category: 'Social', description: 'Photos, reels, profiles' },
|
|
603
|
+
{ domain: 'tiktok.com', category: 'Social', description: 'Video metadata, captions' },
|
|
604
|
+
{ domain: 'pinterest.com', category: 'Social', description: 'Pins, boards' },
|
|
605
|
+
{ domain: 'linkedin.com', category: 'Social', description: 'Profiles, job listings' },
|
|
606
|
+
{ domain: 'facebook.com', category: 'Social', description: 'Marketplace listings' },
|
|
607
|
+
// Video / Audio
|
|
608
|
+
{ domain: 'youtube.com', category: 'Video', description: 'Transcripts, metadata, comments' },
|
|
609
|
+
{ domain: 'twitch.tv', category: 'Video', description: 'Streams, clips, channel info' },
|
|
610
|
+
{ domain: 'soundcloud.com', category: 'Audio', description: 'Tracks, playlists' },
|
|
611
|
+
{ domain: 'open.spotify.com', category: 'Audio', description: 'Tracks, albums, playlists' },
|
|
612
|
+
// Tech / Dev
|
|
613
|
+
{ domain: 'github.com', category: 'Dev', description: 'Repos, issues, PRs, code' },
|
|
614
|
+
{ domain: 'stackoverflow.com', category: 'Dev', description: 'Questions, answers' },
|
|
615
|
+
{ domain: 'npmjs.com', category: 'Dev', description: 'Package metadata, readme' },
|
|
616
|
+
{ domain: 'pypi.org', category: 'Dev', description: 'Package metadata, readme' },
|
|
617
|
+
{ domain: 'dev.to', category: 'Dev', description: 'Articles, comments' },
|
|
618
|
+
// News / Articles
|
|
619
|
+
{ domain: 'news.ycombinator.com', category: 'News', description: 'HN posts, comments, Ask/Show HN' },
|
|
620
|
+
{ domain: 'medium.com', category: 'Articles', description: 'Articles, publications' },
|
|
621
|
+
{ domain: 'substack.com / *.substack.com', category: 'Articles', description: 'Newsletters, posts' },
|
|
622
|
+
{ domain: 'nytimes.com', category: 'News', description: 'Articles, headlines' },
|
|
623
|
+
{ domain: 'bbc.com', category: 'News', description: 'Articles, headlines' },
|
|
624
|
+
{ domain: 'cnn.com', category: 'News', description: 'Articles, headlines' },
|
|
625
|
+
// Shopping / E-commerce
|
|
626
|
+
{ domain: 'amazon.com', category: 'Shopping', description: 'Products, prices, reviews' },
|
|
627
|
+
{ domain: 'bestbuy.com', category: 'Shopping', description: 'Products, prices, specs' },
|
|
628
|
+
{ domain: 'walmart.com', category: 'Shopping', description: 'Products, prices' },
|
|
629
|
+
{ domain: 'ebay.com', category: 'Shopping', description: 'Listings, prices' },
|
|
630
|
+
{ domain: 'etsy.com', category: 'Shopping', description: 'Handmade listings' },
|
|
631
|
+
// Local / Real Estate
|
|
632
|
+
{ domain: 'yelp.com', category: 'Local', description: 'Business info, reviews (needs YELP_API_KEY)' },
|
|
633
|
+
{ domain: 'craigslist.org', category: 'Local', description: 'Listings, classifieds' },
|
|
634
|
+
{ domain: 'zillow.com', category: 'Real Estate', description: 'Property listings, estimates' },
|
|
635
|
+
{ domain: 'redfin.com', category: 'Real Estate', description: 'Property listings, prices' },
|
|
636
|
+
{ domain: 'cars.com', category: 'Automotive', description: 'Car listings, prices' },
|
|
637
|
+
// Knowledge / Academic
|
|
638
|
+
{ domain: 'en.wikipedia.org', category: 'Knowledge', description: 'Articles, structured data' },
|
|
639
|
+
{ domain: 'arxiv.org', category: 'Academic', description: 'Papers, abstracts, metadata' },
|
|
640
|
+
{ domain: 'semanticscholar.org', category: 'Academic', description: 'Papers, citations' },
|
|
641
|
+
{ domain: 'pubmed.ncbi.nlm.nih.gov', category: 'Academic', description: 'Medical papers, abstracts' },
|
|
642
|
+
{ domain: 'imdb.com', category: 'Knowledge', description: 'Movies, TV shows, cast' },
|
|
643
|
+
{ domain: 'allrecipes.com', category: 'Knowledge', description: 'Recipes, ingredients, steps' },
|
|
644
|
+
// Finance / Markets
|
|
645
|
+
{ domain: 'polymarket.com', category: 'Finance', description: 'Prediction markets' },
|
|
646
|
+
{ domain: 'kalshi.com', category: 'Finance', description: 'Prediction markets' },
|
|
647
|
+
{ domain: 'tradingview.com', category: 'Finance', description: 'Charts, indicators, ideas' },
|
|
648
|
+
{ domain: 'coingecko.com', category: 'Finance', description: 'Crypto prices, market data' },
|
|
649
|
+
{ domain: 'coinmarketcap.com', category: 'Finance', description: 'Crypto prices, market data' },
|
|
650
|
+
// Sports / Betting
|
|
651
|
+
{ domain: 'espn.com', category: 'Sports', description: 'Scores, stats, news' },
|
|
652
|
+
{ domain: 'draftkings.com', category: 'Betting', description: 'Odds, lines' },
|
|
653
|
+
{ domain: 'fanduel.com', category: 'Betting', description: 'Odds, lines' },
|
|
654
|
+
{ domain: 'betmgm.com', category: 'Betting', description: 'Odds, lines' },
|
|
655
|
+
// Entertainment
|
|
656
|
+
{ domain: 'producthunt.com', category: 'Tech', description: 'Product launches, upvotes' },
|
|
657
|
+
// Documents
|
|
658
|
+
{ domain: '*.pdf URLs', category: 'Documents', description: 'PDF text extraction' },
|
|
659
|
+
// Weather
|
|
660
|
+
{ domain: 'weather.com', category: 'Weather', description: 'Forecasts, conditions' },
|
|
661
|
+
{ domain: 'accuweather.com', category: 'Weather', description: 'Forecasts, conditions' },
|
|
662
|
+
{ domain: 'api.open-meteo.com', category: 'Weather', description: 'Free weather API' },
|
|
663
|
+
];
|
|
664
|
+
if (options.json) {
|
|
665
|
+
console.log(JSON.stringify(extractors, null, 2));
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
// Group by category
|
|
669
|
+
const byCategory = new Map();
|
|
670
|
+
for (const e of extractors) {
|
|
671
|
+
if (!byCategory.has(e.category))
|
|
672
|
+
byCategory.set(e.category, []);
|
|
673
|
+
byCategory.get(e.category).push(e);
|
|
674
|
+
}
|
|
675
|
+
console.log(`\n🔌 WebPeel Domain Extractors (${extractors.length} total)\n`);
|
|
676
|
+
for (const [cat, items] of byCategory) {
|
|
677
|
+
console.log(` ${cat}`);
|
|
678
|
+
for (const item of items) {
|
|
679
|
+
const pad = 35;
|
|
680
|
+
const domainPad = item.domain.padEnd(pad);
|
|
681
|
+
console.log(` ${domainPad} ${item.description}`);
|
|
682
|
+
}
|
|
683
|
+
console.log('');
|
|
684
|
+
}
|
|
685
|
+
console.log(' Run `webpeel <url>` to use these automatically based on the URL.');
|
|
686
|
+
});
|
|
591
687
|
}
|
package/dist/cli/utils.js
CHANGED
|
@@ -255,7 +255,37 @@ export async function fetchViaApi(url, options, apiKey, apiUrl) {
|
|
|
255
255
|
err.statusCode = res.status;
|
|
256
256
|
throw err;
|
|
257
257
|
}
|
|
258
|
-
|
|
258
|
+
let data = await res.json();
|
|
259
|
+
// Handle async job queue mode — API returns { jobId, pollUrl } and we need to poll
|
|
260
|
+
if (data.jobId && data.pollUrl && !data.content) {
|
|
261
|
+
const pollEndpoint = `${apiUrl}${data.pollUrl}`;
|
|
262
|
+
const maxPollMs = 90_000; // 90s max
|
|
263
|
+
const pollInterval = 1_000; // 1s intervals
|
|
264
|
+
const start = Date.now();
|
|
265
|
+
while (Date.now() - start < maxPollMs) {
|
|
266
|
+
await new Promise(r => setTimeout(r, pollInterval));
|
|
267
|
+
const pollRes = await fetch(pollEndpoint, {
|
|
268
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
269
|
+
signal: AbortSignal.timeout(10_000),
|
|
270
|
+
});
|
|
271
|
+
if (!pollRes.ok) {
|
|
272
|
+
throw new Error(`Job poll failed: HTTP ${pollRes.status}`);
|
|
273
|
+
}
|
|
274
|
+
const pollData = await pollRes.json();
|
|
275
|
+
if (pollData.status === 'completed' || pollData.content) {
|
|
276
|
+
data = pollData.result || pollData;
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
if (pollData.status === 'failed' || pollData.status === 'error') {
|
|
280
|
+
throw new Error(pollData.error?.message || pollData.error || 'Job failed on server');
|
|
281
|
+
}
|
|
282
|
+
// Still processing — keep polling
|
|
283
|
+
}
|
|
284
|
+
// If we exited the loop without data, warn
|
|
285
|
+
if (!data.content && data.jobId) {
|
|
286
|
+
throw new Error('Job timed out waiting for server response. Try again or use local mode (unset WEBPEEL_API_KEY).');
|
|
287
|
+
}
|
|
288
|
+
}
|
|
259
289
|
// Map API response to PeelResult shape that the CLI already handles
|
|
260
290
|
return {
|
|
261
291
|
url: data.url || url,
|
package/dist/cli.js
CHANGED
|
@@ -14,6 +14,20 @@
|
|
|
14
14
|
* npx webpeel --help - Condensed help
|
|
15
15
|
* npx webpeel --help-all - Full option reference
|
|
16
16
|
*/
|
|
17
|
+
// ── Auto-load .env from cwd (lightweight, no dotenv dependency) ──────────────
|
|
18
|
+
// Must happen BEFORE any imports that read env vars (e.g., WEBPEEL_API_KEY)
|
|
19
|
+
import { readFileSync, existsSync } from 'fs';
|
|
20
|
+
import { resolve } from 'path';
|
|
21
|
+
{
|
|
22
|
+
const envPath = resolve(process.cwd(), '.env');
|
|
23
|
+
if (existsSync(envPath)) {
|
|
24
|
+
for (const line of readFileSync(envPath, 'utf-8').split('\n')) {
|
|
25
|
+
const m = line.match(/^([A-Z_][A-Z0-9_]*)=(.*)$/);
|
|
26
|
+
if (m && !process.env[m[1]])
|
|
27
|
+
process.env[m[1]] = m[2].replace(/^["']|["']$/g, '');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
17
31
|
import { Command } from 'commander';
|
|
18
32
|
import { VERB_ALIASES, cliVersion, checkForUpdates, buildCommanderHelp, buildCondensedHelp, } from './cli/utils.js';
|
|
19
33
|
import { registerFetchCommands } from './cli/commands/fetch.js';
|
|
@@ -22,6 +22,7 @@ export interface SearchFallbackResult {
|
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* Search for a URL using the best available search provider and extract the snippet.
|
|
25
|
+
* Richer fallback: tries multiple engines if the first returns < 100 tokens.
|
|
25
26
|
* Returns the title, snippet, and any extracted product data.
|
|
26
27
|
*/
|
|
27
28
|
export declare function searchFallback(url: string): Promise<SearchFallbackResult>;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Google CSE API → Brave API → Google stealth → DDG
|
|
8
8
|
* This avoids direct HTML scraping which is blocked by CAPTCHAs on datacenter IPs.
|
|
9
9
|
*/
|
|
10
|
-
import { getBestSearchProvider } from './search-provider.js';
|
|
10
|
+
import { getBestSearchProvider, DuckDuckGoProvider } from './search-provider.js';
|
|
11
11
|
/**
|
|
12
12
|
* Detect if a URL is likely a product page.
|
|
13
13
|
*/
|
|
@@ -121,8 +121,15 @@ function buildCachedContent(url, title, snippet, productData) {
|
|
|
121
121
|
lines.push(`*⚠️ Limited content — original page blocked direct access. For full data, configure GOOGLE_SEARCH_KEY or BRAVE_SEARCH_KEY.*`);
|
|
122
122
|
return lines.join('\n');
|
|
123
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Count approximate tokens in a string (1 token ≈ 4 chars).
|
|
126
|
+
*/
|
|
127
|
+
function countTokens(text) {
|
|
128
|
+
return Math.ceil(text.length / 4);
|
|
129
|
+
}
|
|
124
130
|
/**
|
|
125
131
|
* Search for a URL using the best available search provider and extract the snippet.
|
|
132
|
+
* Richer fallback: tries multiple engines if the first returns < 100 tokens.
|
|
126
133
|
* Returns the title, snippet, and any extracted product data.
|
|
127
134
|
*/
|
|
128
135
|
export async function searchFallback(url) {
|
|
@@ -142,16 +149,42 @@ export async function searchFallback(url) {
|
|
|
142
149
|
}
|
|
143
150
|
const searchQuery = buildSearchQuery(url);
|
|
144
151
|
const { provider, apiKey } = getBestSearchProvider();
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
152
|
+
// Map provider ID to our source type
|
|
153
|
+
const sourceMap = {
|
|
154
|
+
duckduckgo: 'duckduckgo',
|
|
155
|
+
brave: 'google',
|
|
156
|
+
stealth: 'duckduckgo',
|
|
157
|
+
google: 'google',
|
|
158
|
+
};
|
|
159
|
+
// Try the primary (best) provider first
|
|
160
|
+
let results = await provider.searchWeb(searchQuery, { count: 5, apiKey }).catch(() => []);
|
|
161
|
+
// If primary returns sparse results (< 100 tokens), try DDG as secondary
|
|
162
|
+
const combinedSnippets = [];
|
|
163
|
+
let title = '';
|
|
164
|
+
let source = sourceMap[provider.id] ?? 'google';
|
|
165
|
+
if (results.length > 0) {
|
|
166
|
+
title = results[0].title?.trim() || '';
|
|
167
|
+
combinedSnippets.push(...results.map(r => r.snippet?.trim()).filter(Boolean));
|
|
168
|
+
}
|
|
169
|
+
const primaryTokens = countTokens(combinedSnippets.join(' '));
|
|
170
|
+
if (primaryTokens < 100) {
|
|
171
|
+
// Try DDG as a secondary engine to supplement
|
|
172
|
+
try {
|
|
173
|
+
const ddgProvider = new DuckDuckGoProvider();
|
|
174
|
+
const ddgResults = await ddgProvider.searchWeb(searchQuery, { count: 5 });
|
|
175
|
+
if (ddgResults.length > 0) {
|
|
176
|
+
if (!title)
|
|
177
|
+
title = ddgResults[0].title?.trim() || '';
|
|
178
|
+
if (source !== 'duckduckgo')
|
|
179
|
+
source = 'duckduckgo';
|
|
180
|
+
combinedSnippets.push(...ddgResults.map(r => r.snippet?.trim()).filter(Boolean));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
catch { /* ignore secondary failure */ }
|
|
151
184
|
}
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
const snippet =
|
|
185
|
+
// Also try Google Cache URL as a last-resort content source
|
|
186
|
+
const allSnippets = [...new Set(combinedSnippets)]; // deduplicate
|
|
187
|
+
const snippet = allSnippets.slice(0, 3).join('\n\n');
|
|
155
188
|
if (!title && !snippet) {
|
|
156
189
|
return emptyResult;
|
|
157
190
|
}
|
|
@@ -159,14 +192,6 @@ export async function searchFallback(url) {
|
|
|
159
192
|
? extractProductData(title, snippet)
|
|
160
193
|
: undefined;
|
|
161
194
|
const cachedContent = buildCachedContent(url, title, snippet, productData);
|
|
162
|
-
// Map provider ID to our source type
|
|
163
|
-
const sourceMap = {
|
|
164
|
-
duckduckgo: 'duckduckgo',
|
|
165
|
-
brave: 'google',
|
|
166
|
-
stealth: 'duckduckgo',
|
|
167
|
-
google: 'google',
|
|
168
|
-
};
|
|
169
|
-
const source = sourceMap[provider.id] ?? 'google';
|
|
170
195
|
return {
|
|
171
196
|
title,
|
|
172
197
|
snippet,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webpeel",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.73",
|
|
4
4
|
"description": "Fast web fetcher for AI agents - stealth mode, crawl mode, page actions, structured extraction, PDF parsing, smart escalation from simple HTTP to headless browser",
|
|
5
5
|
"author": "Jake Liu",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"main": "./dist/index.js",
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
10
|
"bin": {
|
|
11
|
-
"webpeel": "dist/cli.
|
|
11
|
+
"webpeel": "dist/cli.js"
|
|
12
12
|
},
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|