Spaces:
Paused
Paused
Feat: Migrate from DuckDuckGo HTML scraping to reliable Google News RSS parsing for bypassing HuggingFace IP blocks
Browse files- index.html +1 -1
- server/news-service.js +15 -26
index.html
CHANGED
|
@@ -51,7 +51,7 @@
|
|
| 51 |
</head>
|
| 52 |
<body class="dark-theme in-chat-view">
|
| 53 |
|
| 54 |
-
<div id="live-version-badge" style="position: fixed; top: 50px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--text-secondary); opacity: 0.6; z-index: 99999; pointer-events: none; font-weight: 500; font-family: monospace; letter-spacing: 1px; background: rgba(0,0,0,0.2); padding: 2px 8px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.05);">BUILD 1.3.
|
| 55 |
|
| 56 |
<!-- SVG Filters for Liquid Glass Refraction -->
|
| 57 |
<svg width="0" height="0" style="position: absolute; pointer-events: none;">
|
|
|
|
| 51 |
</head>
|
| 52 |
<body class="dark-theme in-chat-view">
|
| 53 |
|
| 54 |
+
<div id="live-version-badge" style="position: fixed; top: 50px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--text-secondary); opacity: 0.6; z-index: 99999; pointer-events: none; font-weight: 500; font-family: monospace; letter-spacing: 1px; background: rgba(0,0,0,0.2); padding: 2px 8px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.05);">BUILD 1.3.3</div>
|
| 55 |
|
| 56 |
<!-- SVG Filters for Liquid Glass Refraction -->
|
| 57 |
<svg width="0" height="0" style="position: absolute; pointer-events: none;">
|
server/news-service.js
CHANGED
|
@@ -47,41 +47,30 @@ function saveData() {
|
|
| 47 |
}
|
| 48 |
}
|
| 49 |
|
| 50 |
-
//
|
| 51 |
async function searchDDG(query) {
|
| 52 |
try {
|
| 53 |
-
const
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
}
|
| 58 |
-
});
|
| 59 |
-
const html = await res.text();
|
| 60 |
-
const $ = cheerio.load(html);
|
| 61 |
|
| 62 |
const results = [];
|
| 63 |
-
$('
|
| 64 |
-
if (i >= 5) return;
|
| 65 |
-
const title = $(el).find('
|
| 66 |
-
const
|
| 67 |
-
const
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
let actualUrl = link;
|
| 71 |
-
if (link && link.startsWith('//duckduckgo.com/l/?uddg=')) {
|
| 72 |
-
try {
|
| 73 |
-
const urlParam = new URL('https:' + link).searchParams.get('uddg');
|
| 74 |
-
if (urlParam) actualUrl = decodeURIComponent(urlParam);
|
| 75 |
-
} catch(e){}
|
| 76 |
-
}
|
| 77 |
|
| 78 |
-
if (title &&
|
| 79 |
-
results.push({ title, snippet, url:
|
| 80 |
}
|
| 81 |
});
|
| 82 |
return results;
|
| 83 |
} catch (e) {
|
| 84 |
-
console.error('[NewsService]
|
| 85 |
return [];
|
| 86 |
}
|
| 87 |
}
|
|
|
|
| 47 |
}
|
| 48 |
}
|
| 49 |
|
| 50 |
+
// Search Web (Google News RSS)
|
| 51 |
async function searchDDG(query) {
|
| 52 |
try {
|
| 53 |
+
const url = `https://news.google.com/rss/search?q=${encodeURIComponent(query)}&hl=de&gl=DE&ceid=DE:de`;
|
| 54 |
+
const res = await fetch(url);
|
| 55 |
+
const xml = await res.text();
|
| 56 |
+
const $ = cheerio.load(xml, { xmlMode: true });
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
const results = [];
|
| 59 |
+
$('item').each((i, el) => {
|
| 60 |
+
if (i >= 5) return;
|
| 61 |
+
const title = $(el).find('title').text();
|
| 62 |
+
const link = $(el).find('link').text();
|
| 63 |
+
const description = $(el).find('description').text();
|
| 64 |
+
// Strip HTML tags from description snippet
|
| 65 |
+
const snippet = cheerio.load(description).text().trim() || title;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
+
if (title && link) {
|
| 68 |
+
results.push({ title, snippet, url: link });
|
| 69 |
}
|
| 70 |
});
|
| 71 |
return results;
|
| 72 |
} catch (e) {
|
| 73 |
+
console.error('[NewsService] RSS Search Error:', e);
|
| 74 |
return [];
|
| 75 |
}
|
| 76 |
}
|