Spaces:
Running
Running
Download index.html from cruelface/webcrawler: direct link, hf CLI and curl.
- Browser
- Download file 36.2 kB
-
https://huggingface.co/spaces/cruelface/webcrawler/resolve/main/index.html
- Command line
-
hf download hf://spaces/cruelface/webcrawler/index.html
-
curl -L -o index.html https://huggingface.co/spaces/cruelface/webcrawler/resolve/main/index.html
36.2 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Enhanced Affiliate Link Crawler</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> | |
| <style> | |
| .gradient-bg { | |
| background: linear-gradient(135deg, #6b73ff 0%, #000dff 100%); | |
| } | |
| .result-card { | |
| transition: all 0.3s ease; | |
| border-left: 4px solid #4f46e5; | |
| } | |
| .result-card:hover { | |
| transform: translateY(-2px); | |
| box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1); | |
| } | |
| .pulse { | |
| animation: pulse 2s infinite; | |
| } | |
| @keyframes pulse { | |
| 0% { opacity: 1; } | |
| 50% { opacity: 0.5; } | |
| 100% { opacity: 1; } | |
| } | |
| .status-badge { | |
| font-size: 0.7rem; | |
| padding: 0.2rem 0.5rem; | |
| border-radius: 9999px; | |
| } | |
| .badge-new { | |
| background-color: #10b981; | |
| } | |
| .badge-redirect { | |
| background-color: #f59e0b; | |
| } | |
| .badge-js { | |
| background-color: #3b82f6; | |
| } | |
| .badge-image { | |
| background-color: #8b5cf6; | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gray-50 min-h-screen"> | |
| <div class="gradient-bg text-white py-6 shadow-lg"> | |
| <div class="container mx-auto px-4"> | |
| <div class="flex items-center justify-between"> | |
| <div> | |
| <h1 class="text-3xl font-bold"><i class="fas fa-spider mr-2"></i>Enhanced Affiliate Link Crawler</h1> | |
| <p class="mt-2 opacity-90">Discover hidden affiliate links and banners across websites</p> | |
| </div> | |
| <div class="bg-white/20 p-3 rounded-full"> | |
| <i class="fas fa-link text-2xl"></i> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="container mx-auto px-4 py-8"> | |
| <div class="bg-white rounded-xl shadow-md overflow-hidden"> | |
| <div class="p-6"> | |
| <h2 class="text-2xl font-semibold text-gray-800 mb-4">Crawler Configuration</h2> | |
| <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-6"> | |
| <div> | |
| <label class="block text-sm font-medium text-gray-700 mb-1">Website URL</label> | |
| <div class="relative"> | |
| <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none"> | |
| <i class="fas fa-globe text-gray-400"></i> | |
| </div> | |
| <input type="text" id="urlInput" class="pl-10 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 py-2 px-3 border" placeholder="https://example.com" value="https://example.com"> | |
| </div> | |
| </div> | |
| <div> | |
| <label class="block text-sm font-medium text-gray-700 mb-1">Max Pages per Section</label> | |
| <div class="relative"> | |
| <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none"> | |
| <i class="fas fa-file-alt text-gray-400"></i> | |
| </div> | |
| <input type="number" id="maxPages" class="pl-10 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 py-2 px-3 border" min="1" value="9"> | |
| </div> | |
| </div> | |
| <div> | |
| <label class="block text-sm font-medium text-gray-700 mb-1">Crawl Depth</label> | |
| <select id="crawlDepth" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 py-2 px-3 border"> | |
| <option value="1">Shallow (Homepage only)</option> | |
| <option value="2" selected>Standard (Home + Categories)</option> | |
| <option value="3">Deep (All internal links)</option> | |
| </select> | |
| </div> | |
| </div> | |
| <div class="flex space-x-4"> | |
| <button id="startBtn" class="bg-indigo-600 hover:bg-indigo-700 text-white font-medium py-2 px-6 rounded-md flex items-center"> | |
| <i class="fas fa-play mr-2"></i> Start Crawling | |
| </button> | |
| <button id="stopBtn" class="bg-gray-200 hover:bg-gray-300 text-gray-800 font-medium py-2 px-6 rounded-md flex items-center"> | |
| <i class="fas fa-stop mr-2"></i> Stop & Reset | |
| </button> | |
| <button id="exportBtn" class="bg-green-600 hover:bg-green-700 text-white font-medium py-2 px-6 rounded-md flex items-center"> | |
| <i class="fas fa-file-export mr-2"></i> Export Results | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="grid grid-cols-1 lg:grid-cols-3 gap-6 mt-8"> | |
| <div class="lg:col-span-2"> | |
| <div class="bg-white rounded-xl shadow-md overflow-hidden"> | |
| <div class="p-6"> | |
| <div class="flex justify-between items-center mb-4"> | |
| <h2 class="text-2xl font-semibold text-gray-800">Detection Results</h2> | |
| <span id="resultCount" class="bg-indigo-100 text-indigo-800 text-sm font-medium px-3 py-1 rounded-full">0 matches</span> | |
| </div> | |
| <div id="resultsContainer" class="space-y-4"> | |
| <div class="text-center py-12 text-gray-400"> | |
| <i class="fas fa-search fa-3x mb-4"></i> | |
| <p class="text-lg">No results yet. Start crawling to find affiliate links.</p> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div> | |
| <div class="bg-white rounded-xl shadow-md overflow-hidden"> | |
| <div class="p-6"> | |
| <div class="flex justify-between items-center mb-4"> | |
| <h2 class="text-2xl font-semibold text-gray-800">Crawl Status</h2> | |
| <div id="crawlStatus" class="flex items-center"> | |
| <span class="h-3 w-3 bg-gray-300 rounded-full mr-2"></span> | |
| <span class="text-sm text-gray-500">Idle</span> | |
| </div> | |
| </div> | |
| <div class="mb-4"> | |
| <div class="flex justify-between text-sm text-gray-600 mb-1"> | |
| <span>Progress</span> | |
| <span id="progressText">0%</span> | |
| </div> | |
| <div class="w-full bg-gray-200 rounded-full h-2.5"> | |
| <div id="progressBar" class="bg-indigo-600 h-2.5 rounded-full" style="width: 0%"></div> | |
| </div> | |
| </div> | |
| <div id="statusContainer" class="border rounded-lg p-4 bg-gray-50 max-h-96 overflow-y-auto"> | |
| <div class="text-gray-500 text-sm">Waiting to start...</div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="bg-white rounded-xl shadow-md overflow-hidden mt-6"> | |
| <div class="p-6"> | |
| <h2 class="text-2xl font-semibold text-gray-800 mb-4">Detection Statistics</h2> | |
| <div class="grid grid-cols-2 gap-4"> | |
| <div class="bg-indigo-50 p-4 rounded-lg"> | |
| <div class="text-indigo-800 font-bold text-xl" id="directLinks">0</div> | |
| <div class="text-indigo-600 text-sm">Direct Links</div> | |
| </div> | |
| <div class="bg-yellow-50 p-4 rounded-lg"> | |
| <div class="text-yellow-800 font-bold text-xl" id="redirectLinks">0</div> | |
| <div class="text-yellow-600 text-sm">Redirect Links</div> | |
| </div> | |
| <div class="bg-blue-50 p-4 rounded-lg"> | |
| <div class="text-blue-800 font-bold text-xl" id="jsLinks">0</div> | |
| <div class="text-blue-600 text-sm">JS Links</div> | |
| </div> | |
| <div class="bg-purple-50 p-4 rounded-lg"> | |
| <div class="text-purple-800 font-bold text-xl" id="imageLinks">0</div> | |
| <div class="text-purple-600 text-sm">Image Links</div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| // Enhanced Web Crawler JavaScript Implementation | |
| class EnhancedWebCrawler { | |
| constructor(startUrl, maxPages = 9, crawlDepth = 2) { | |
| this.startUrl = startUrl; | |
| this.maxPages = maxPages; | |
| this.crawlDepth = crawlDepth; | |
| this.keywords = ["gowithguide", "go with guide", "go-with-guide", "87121"]; | |
| this.mainDomain = this.extractDomain(startUrl); | |
| this.visited = new Set(); | |
| this.results = []; | |
| this.queue = []; | |
| this.categories = []; | |
| this.currentCategory = null; | |
| this.statusMessages = []; | |
| this.userStopped = false; | |
| this.pagesCrawled = 0; | |
| this.redirectCache = {}; | |
| this.stats = { | |
| direct: 0, | |
| redirect: 0, | |
| js: 0, | |
| image: 0 | |
| }; | |
| } | |
| extractDomain(url) { | |
| try { | |
| const domain = new URL(url).hostname.replace('www.', ''); | |
| return domain.startsWith('http') ? domain : `https://${domain}`; | |
| } catch { | |
| return url.replace('www.', '').split('/')[0]; | |
| } | |
| } | |
| isSubdomainOf(url) { | |
| const main = this.mainDomain.replace('www.', '').toLowerCase(); | |
| const testDomain = url.replace('www.', '').toLowerCase(); | |
| return testDomain === main || testDomain.endsWith(`.${main}`); | |
| } | |
| async resolveRedirects(url) { | |
| if (this.redirectCache[url]) { | |
| return this.redirectCache[url]; | |
| } | |
| try { | |
| // Simulate HEAD request with fetch | |
| const response = await fetch(url, { | |
| method: 'HEAD', | |
| redirect: 'manual', | |
| headers: { 'User-Agent': 'Mozilla/5.0' } | |
| }); | |
| let finalUrl = url; | |
| const history = []; | |
| // Handle redirects | |
| if (response.redirected) { | |
| finalUrl = response.url; | |
| // In a real implementation, we'd track the redirect chain | |
| history.push(url); | |
| } | |
| this.redirectCache[url] = { finalUrl, history }; | |
| return { finalUrl, history }; | |
| } catch (error) { | |
| this.addStatusMessage(`Error resolving redirects for ${url}: ${error.message}`); | |
| return { finalUrl: url, history: [] }; | |
| } | |
| } | |
| getMatchedKeywords(text) { | |
| if (!text) return []; | |
| const textLower = String(text).toLowerCase().trim(); | |
| const exactMatches = new Set(); | |
| // Check for exact keyword matches | |
| this.keywords.forEach(kw => { | |
| const kwLower = kw.toLowerCase(); | |
| if (kwLower.includes(' ') && textLower.includes(kwLower)) { | |
| exactMatches.add(kw); | |
| } else if (textLower.includes(kwLower)) { | |
| exactMatches.add(kw); | |
| } | |
| // Check URL encoded versions | |
| const kwEncoded = encodeURIComponent(kw); | |
| if (textLower.includes(kwEncoded.toLowerCase())) { | |
| exactMatches.add(kw); | |
| } | |
| }); | |
| // Check URL patterns | |
| const urlPatterns = [ | |
| /(?:https?:\/\/)?(?:www\.)?gowithguide\.com/i, | |
| /utm_source=([^&]*)/i, | |
| /utm_campaign=([^&]*)/i, | |
| /sv1=([^&]*)/i, | |
| /awc=([^&]*)/i, | |
| /87121(?:_\d+|%5F\d+)?/i | |
| ]; | |
| urlPatterns.forEach(pattern => { | |
| const matches = textLower.match(pattern); | |
| if (matches) { | |
| matches.forEach(match => { | |
| if (typeof match === 'string') { | |
| this.keywords.forEach(kw => { | |
| if (match.toLowerCase().includes(kw.toLowerCase())) { | |
| exactMatches.add(kw); | |
| } | |
| }); | |
| } | |
| }); | |
| } | |
| }); | |
| return Array.from(exactMatches); | |
| } | |
| async checkUrlForKeywords(url, sourceUrl) { | |
| const matchedKws = this.getMatchedKeywords(url); | |
| if (matchedKws.length > 0) { | |
| this.addResult({ | |
| sourceUrl, | |
| matchedUrl: url, | |
| element: 'url', | |
| attribute: 'href', | |
| content: url, | |
| keywords: matchedKws, | |
| locationType: 'direct_url' | |
| }); | |
| this.stats.direct++; | |
| } | |
| // Check redirects | |
| const { finalUrl, history } = await this.resolveRedirects(url); | |
| if (finalUrl !== url) { | |
| const matchedKwsFinal = this.getMatchedKeywords(finalUrl); | |
| if (matchedKwsFinal.length > 0) { | |
| this.addResult({ | |
| sourceUrl, | |
| matchedUrl: finalUrl, | |
| element: 'url', | |
| attribute: 'href', | |
| content: `Redirected from: ${url} to: ${finalUrl}`, | |
| keywords: matchedKwsFinal, | |
| locationType: 'redirected_url' | |
| }); | |
| this.stats.redirect++; | |
| } | |
| // Check intermediate URLs in redirect chain | |
| for (const intermediateUrl of history) { | |
| const matchedKwsIntermediate = this.getMatchedKeywords(intermediateUrl); | |
| if (matchedKwsIntermediate.length > 0) { | |
| this.addResult({ | |
| sourceUrl, | |
| matchedUrl: intermediateUrl, | |
| element: 'url', | |
| attribute: 'href', | |
| content: `Redirect chain URL: ${intermediateUrl}`, | |
| keywords: matchedKwsIntermediate, | |
| locationType: 'redirect_chain_url' | |
| }); | |
| this.stats.redirect++; | |
| } | |
| } | |
| } | |
| // Check URL parameters | |
| try { | |
| const urlObj = new URL(url); | |
| const params = urlObj.searchParams; | |
| params.forEach((value, key) => { | |
| const paramMatch = this.getMatchedKeywords(`${key}=${value}`); | |
| if (paramMatch.length > 0) { | |
| this.addResult({ | |
| sourceUrl, | |
| matchedUrl: url, | |
| element: 'param', | |
| attribute: key, | |
| content: value, | |
| keywords: paramMatch, | |
| locationType: 'url_parameter' | |
| }); | |
| } | |
| }); | |
| } catch (e) { | |
| // Invalid URL, skip parameter check | |
| } | |
| } | |
| async processUrl(url) { | |
| if (this.visited.has(url) || this.pagesCrawled >= this.maxPages) { | |
| return []; | |
| } | |
| this.visited.add(url); | |
| this.pagesCrawled++; | |
| this.addStatusMessage(`Crawling: ${url}`); | |
| try { | |
| // Simulate fetching the page | |
| const response = await fetch(`https://api.allorigins.win/get?url=${encodeURIComponent(url)}`); | |
| const data = await response.json(); | |
| if (data.contents) { | |
| // Simulate parsing HTML with a simple regex approach | |
| const html = data.contents; | |
| // Check for links in href attributes | |
| const hrefMatches = html.match(/href=["']([^"']+)["']/gi) || []; | |
| for (const match of hrefMatches) { | |
| const href = match.replace(/href=["']|["']/gi, '').trim(); | |
| if (href) { | |
| await this.checkUrlForKeywords(href, url); | |
| // Check if this is an image link | |
| if (html.includes(`<img`) && html.includes(`href="${href}"`)) { | |
| const imgAltMatches = html.match(/alt=["']([^"']+)["']/gi) || []; | |
| for (const altMatch of imgAltMatches) { | |
| const altText = altMatch.replace(/alt=["']|["']/gi, '').trim(); | |
| const matchedKws = this.getMatchedKeywords(altText); | |
| if (matchedKws.length > 0) { | |
| this.addResult({ | |
| sourceUrl: url, | |
| matchedUrl: href, | |
| element: 'img', | |
| attribute: 'alt', | |
| content: altText, | |
| keywords: matchedKws, | |
| locationType: 'image_banner' | |
| }); | |
| this.stats.image++; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| // Check for JavaScript links | |
| const scriptMatches = html.match(/<script[^>]*>([\s\S]*?)<\/script>/gi) || []; | |
| for (const script of scriptMatches) { | |
| const jsUrlMatches = script.match(/https?:\/\/[^\s'"]+/gi) || []; | |
| for (const jsUrl of jsUrlMatches) { | |
| await this.checkUrlForKeywords(jsUrl, url); | |
| this.stats.js++; | |
| } | |
| } | |
| // Check for meta tags | |
| const metaMatches = html.match(/<meta[^>]+>/gi) || []; | |
| for (const metaTag of metaMatches) { | |
| const contentMatch = metaTag.match(/content=["']([^"']+)["']/i); | |
| if (contentMatch) { | |
| const content = contentMatch[1]; | |
| const matchedKws = this.getMatchedKeywords(content); | |
| if (matchedKws.length > 0) { | |
| const nameMatch = metaTag.match(/name=["']([^"']+)["']/i) || | |
| metaTag.match(/property=["']([^"']+)["']/i); | |
| const attrName = nameMatch ? nameMatch[1] : 'meta'; | |
| this.addResult({ | |
| sourceUrl: url, | |
| matchedUrl: url, | |
| element: 'meta', | |
| attribute: attrName, | |
| content: content, | |
| keywords: matchedKws, | |
| locationType: 'meta_tag' | |
| }); | |
| } | |
| } | |
| } | |
| // Check for text content | |
| const textContent = html.replace(/<[^>]+>/g, ' '); | |
| const textMatches = this.getMatchedKeywords(textContent); | |
| if (textMatches.length > 0) { | |
| this.addResult({ | |
| sourceUrl: url, | |
| matchedUrl: url, | |
| element: 'text', | |
| attribute: 'content', | |
| content: textContent.substring(0, 500), | |
| keywords: textMatches, | |
| locationType: 'page_content' | |
| }); | |
| } | |
| } | |
| } catch (error) { | |
| this.addStatusMessage(`Error fetching ${url}: ${error.message}`); | |
| } | |
| return []; | |
| } | |
| addResult(result) { | |
| this.results.push({ | |
| ...result, | |
| timestamp: new Date().toISOString() | |
| }); | |
| this.updateUI(); | |
| } | |
| addStatusMessage(message) { | |
| this.statusMessages.push(message); | |
| this.updateUI(); | |
| } | |
| updateUI() { | |
| // Update results count | |
| document.getElementById('resultCount').textContent = `${this.results.length} matches`; | |
| // Update status messages | |
| const statusContainer = document.getElementById('statusContainer'); | |
| statusContainer.innerHTML = this.statusMessages.slice(-10).map(msg => | |
| `<div class="text-sm py-1 border-b border-gray-100">${msg}</div>` | |
| ).join(''); | |
| // Update progress | |
| const progress = Math.min(100, (this.pagesCrawled / this.maxPages) * 100); | |
| document.getElementById('progressBar').style.width = `${progress}%`; | |
| document.getElementById('progressText').textContent = `${Math.round(progress)}%`; | |
| // Update stats | |
| document.getElementById('directLinks').textContent = this.stats.direct; | |
| document.getElementById('redirectLinks').textContent = this.stats.redirect; | |
| document.getElementById('jsLinks').textContent = this.stats.js; | |
| document.getElementById('imageLinks').textContent = this.stats.image; | |
| // Update results display | |
| const resultsContainer = document.getElementById('resultsContainer'); | |
| if (this.results.length > 0) { | |
| resultsContainer.innerHTML = this.results.slice(-5).map((result, i) => ` | |
| <div class="result-card bg-white p-4 rounded-lg shadow-sm"> | |
| <div class="flex justify-between items-start mb-2"> | |
| <h3 class="font-medium text-indigo-700">Match ${this.results.length - i}</h3> | |
| <span class="status-badge ${this.getBadgeClass(result.locationType)}"> | |
| ${this.getLocationTypeLabel(result.locationType)} | |
| </span> | |
| </div> | |
| <div class="text-sm text-gray-600 mb-2"> | |
| <span class="font-medium">Source:</span> | |
| <a href="${result.sourceUrl}" target="_blank" class="text-indigo-600 hover:underline">${this.truncateUrl(result.sourceUrl)}</a> | |
| </div> | |
| <div class="text-sm text-gray-600 mb-2"> | |
| <span class="font-medium">Matched URL:</span> | |
| <a href="${result.matchedUrl}" target="_blank" class="text-indigo-600 hover:underline">${this.truncateUrl(result.matchedUrl)}</a> | |
| </div> | |
| <div class="text-sm text-gray-600 mb-2"> | |
| <span class="font-medium">Found in:</span> ${result.element} (${result.attribute}) | |
| </div> | |
| <div class="text-sm text-gray-600"> | |
| <span class="font-medium">Content:</span> ${this.truncateText(result.content, 100)} | |
| </div> | |
| </div> | |
| `).join(''); | |
| } | |
| } | |
| getBadgeClass(locationType) { | |
| switch(locationType) { | |
| case 'direct_url': return 'badge-new'; | |
| case 'redirected_url': | |
| case 'redirect_chain_url': return 'badge-redirect'; | |
| case 'image_banner': return 'badge-image'; | |
| default: return 'badge-js'; | |
| } | |
| } | |
| getLocationTypeLabel(locationType) { | |
| const labels = { | |
| 'direct_url': 'Direct', | |
| 'redirected_url': 'Redirect', | |
| 'redirect_chain_url': 'Redirect', | |
| 'image_banner': 'Image', | |
| 'meta_tag': 'Meta', | |
| 'page_content': 'Text', | |
| 'url_parameter': 'Param' | |
| }; | |
| return labels[locationType] || locationType; | |
| } | |
| truncateUrl(url, maxLength = 40) { | |
| if (url.length <= maxLength) return url; | |
| return url.substring(0, maxLength/2) + '...' + url.substring(url.length - maxLength/2); | |
| } | |
| truncateText(text, maxLength = 100) { | |
| if (!text) return ''; | |
| if (text.length <= maxLength) return text; | |
| return text.substring(0, maxLength) + '...'; | |
| } | |
| async startCrawling() { | |
| this.userStopped = false; | |
| this.addStatusMessage(`Starting crawl of ${this.startUrl}`); | |
| // Crawl homepage first | |
| await this.processUrl(this.startUrl); | |
| if (this.crawlDepth > 1) { | |
| // Get main pages | |
| const mainPages = await this.getMainPages(); | |
| this.addStatusMessage(`Found ${mainPages.length} main pages to crawl`); | |
| for (const page of mainPages.slice(0, this.maxPages)) { | |
| if (this.userStopped) break; | |
| await this.processUrl(page); | |
| } | |
| if (this.crawlDepth > 2) { | |
| // Get categories | |
| this.categories = await this.extractCategories(); | |
| this.addStatusMessage(`Found ${this.categories.length} categories to crawl`); | |
| for (const [catName, catUrl] of this.categories) { | |
| if (this.userStopped) break; | |
| this.addStatusMessage(`Processing category: ${catName}`); | |
| const categoryPages = await this.getCategoryPages(catUrl); | |
| for (const page of categoryPages.slice(0, this.maxPages)) { | |
| if (this.userStopped) break; | |
| await this.processUrl(page); | |
| } | |
| } | |
| } | |
| } | |
| if (!this.userStopped) { | |
| this.addStatusMessage('Crawling completed!'); | |
| document.getElementById('crawlStatus').innerHTML = ` | |
| <span class="h-3 w-3 bg-green-500 rounded-full mr-2"></span> | |
| <span class="text-sm text-gray-700">Completed</span> | |
| `; | |
| } | |
| } | |
| async getMainPages() { | |
| // Simulate finding main pages | |
| return [ | |
| `${this.startUrl}/about`, | |
| `${this.startUrl}/blog`, | |
| `${this.startUrl}/contact`, | |
| `${this.startUrl}/products`, | |
| `${this.startUrl}/services` | |
| ].filter(url => { | |
| try { | |
| const domain = new URL(url).hostname; | |
| return this.isSubdomainOf(domain); | |
| } catch { | |
| return false; | |
| } | |
| }); | |
| } | |
| async extractCategories() { | |
| // Simulate finding categories | |
| return [ | |
| ['travel', `${this.startUrl}/category/travel`], | |
| ['blog', `${this.startUrl}/blog`], | |
| ['resources', `${this.startUrl}/resources`] | |
| ]; | |
| } | |
| async getCategoryPages(categoryUrl) { | |
| // Simulate finding category pages | |
| return [ | |
| `${categoryUrl}/post1`, | |
| `${categoryUrl}/post2`, | |
| `${categoryUrl}/post3`, | |
| `${categoryUrl}/post4` | |
| ]; | |
| } | |
| stopCrawling() { | |
| this.userStopped = true; | |
| this.addStatusMessage('Crawling stopped by user'); | |
| document.getElementById('crawlStatus').innerHTML = ` | |
| <span class="h-3 w-3 bg-red-500 rounded-full mr-2"></span> | |
| <span class="text-sm text-gray-700">Stopped</span> | |
| `; | |
| } | |
| exportResults() { | |
| if (this.results.length === 0) { | |
| alert('No results to export!'); | |
| return; | |
| } | |
| let csvContent = "data:text/csv;charset=utf-8,"; | |
| // Header | |
| csvContent += "Source URL,Matched URL,Keyword,Location Type,Element,Attribute,Content Sample,Timestamp\n"; | |
| // Data | |
| this.results.forEach(result => { | |
| const row = [ | |
| result.sourceUrl, | |
| result.matchedUrl, | |
| result.keyword.join(', '), | |
| result.locationType, | |
| result.element, | |
| result.attribute, | |
| `"${result.content.replace(/"/g, '""')}"`, | |
| result.timestamp | |
| ].join(','); | |
| csvContent += row + "\n"; | |
| }); | |
| // Create download link | |
| const encodedUri = encodeURI(csvContent); | |
| const link = document.createElement("a"); | |
| link.setAttribute("href", encodedUri); | |
| link.setAttribute("download", `affiliate_links_${new Date().toISOString().slice(0,10)}.csv`); | |
| document.body.appendChild(link); | |
| link.click(); | |
| document.body.removeChild(link); | |
| } | |
| } | |
| // UI Event Handlers | |
| document.addEventListener('DOMContentLoaded', () => { | |
| let crawler = null; | |
| document.getElementById('startBtn').addEventListener('click', async () => { | |
| const url = document.getElementById('urlInput').value.trim(); | |
| const maxPages = parseInt(document.getElementById('maxPages').value); | |
| const crawlDepth = parseInt(document.getElementById('crawlDepth').value); | |
| if (!url) { | |
| alert('Please enter a valid URL'); | |
| return; | |
| } | |
| // Reset UI | |
| document.getElementById('resultsContainer').innerHTML = ` | |
| <div class="text-center py-12 text-gray-400"> | |
| <i class="fas fa-spinner fa-spin fa-3x mb-4"></i> | |
| <p class="text-lg">Crawling in progress...</p> | |
| </div> | |
| `; | |
| document.getElementById('crawlStatus').innerHTML = ` | |
| <span class="h-3 w-3 bg-yellow-500 rounded-full mr-2 pulse"></span> | |
| <span class="text-sm text-gray-700">Crawling</span> | |
| `; | |
| // Start crawler | |
| crawler = new EnhancedWebCrawler(url, maxPages, crawlDepth); | |
| crawler.startCrawling(); | |
| }); | |
| document.getElementById('stopBtn').addEventListener('click', () => { | |
| if (crawler) { | |
| crawler.stopCrawling(); | |
| } else { | |
| alert('No active crawler to stop'); | |
| } | |
| }); | |
| document.getElementById('exportBtn').addEventListener('click', () => { | |
| if (crawler) { | |
| crawler.exportResults(); | |
| } else { | |
| alert('No results to export'); | |
| } | |
| }); | |
| }); | |
| </script> | |
| <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=cruelface/webcrawler" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> | |
| </html> |