Luca448 commited on
Commit
2f22263
·
1 Parent(s): 43fb49c

Feat: Migrate from DuckDuckGo HTML scraping to reliable Google News RSS parsing for bypassing HuggingFace IP blocks

Browse files
Files changed (2) hide show
  1. index.html +1 -1
  2. 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.2</div>
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
- // Scrape DDG
51
  async function searchDDG(query) {
52
  try {
53
- const res = await fetch(`https://html.duckduckgo.com/html/?q=${encodeURIComponent(query)}`, {
54
- headers: {
55
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
56
- 'Accept-Language': 'de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7'
57
- }
58
- });
59
- const html = await res.text();
60
- const $ = cheerio.load(html);
61
 
62
  const results = [];
63
- $('.result').each((i, el) => {
64
- if (i >= 5) return; // Top 5
65
- const title = $(el).find('.result__title').text().trim();
66
- const snippet = $(el).find('.result__snippet').text().trim();
67
- const link = $(el).find('.result__url').attr('href') || $(el).find('.result__a').attr('href');
68
-
69
- // DuckDuckGo redirects urls, extract actual url if possible
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 && snippet) {
79
- results.push({ title, snippet, url: actualUrl });
80
  }
81
  });
82
  return results;
83
  } catch (e) {
84
- console.error('[NewsService] DDG Search Error:', e);
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
  }