scraperjavascript143
Tencent Official News & Story Scraper
Scraper resmi website Tencent (tencent.com) untuk mencari berita korporat, inovasi, produk, dan membaca detail artikel lengkap.
Vamz Spectre6 Nov 2026127 baris kode
Jalankan via Terminal / CLI:
# 1. Download file script
curl -sL "https://code.vamxapi.my.id/snippet/raw/tencent" -o tencent.js
# 2. Jalankan script
node tencent.js
tencent.js(127 lines)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/**
* Tencent Official Website & News Scraper
* Author: Vamz Spectre (VamxAPI)
* Target: https://tencent.com
* Description:
* Scrape latest corporate news, articles, and full story content from Tencent's official portal.
*
* Usage CLI:
* curl -sL "https://code.vamxapi.my.id/snippet/raw/tencent" -o tencent.js
* node tencent.js "cloud"
* node tencent.js "https://www.tencent.com/tencent-launches-hy4-joining-the-ranks-of-the-worlds-leading-open-source-ai-models/"
*/
const axios = require('axios');
const cheerio = require('cheerio');
async function tencentScraper(queryOrUrl, page = 1) {
const isUrl = /^https?:\/\/(www\.)?tencent\.com\/.+/i.test(queryOrUrl);
const headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.9,id;q=0.8'
};
if (isUrl) {
// Mode 1: Detail Artikel / Berita
const { data: html } = await axios.get(queryOrUrl, { headers, timeout: 15000 });
const $ = cheerio.load(html);
const title = $('h1').first().text().trim() || $('title').text().replace(/\s*-\s*Tencent.*$/i, '').trim();
const date = $('.entry-header .entry-meta, .tc-blogpost-date, time').first().text().trim().replace(/\s+/g, ' ');
const thumbnail = $('article .wp-post-image, meta[property="og:image"]').first().attr('src') || $('meta[property="og:image"]').attr('content') || null;
const categories = [];
$('.post-categories li a, .tc-blog-cats a').each((_, el) => {
const cat = $(el).text().trim();
if (cat && !categories.includes(cat)) categories.push(cat);
});
const contentParagraphs = [];
$('article .entry-content p, .post-content p, article p').each((_, el) => {
const p = $(el).text().trim();
if (p && !contentParagraphs.includes(p)) {
contentParagraphs.push(p);
}
});
return {
status: true,
type: 'detail',
result: {
title,
url: queryOrUrl,
date: date || null,
thumbnail,
categories,
content: contentParagraphs.join('\n\n')
}
};
}
// Mode 2: Search atau Latest Berita
const query = (queryOrUrl || '').trim();
const endpoint = query
? `https://www.tencent.com/page/${page}/?s=${encodeURIComponent(query)}`
: `https://www.tencent.com/category/corporate/page/${page}/`;
const { data: html } = await axios.get(endpoint, { headers, timeout: 15000 });
const $ = cheerio.load(html);
const items = [];
$('article').each((_, el) => {
const article = $(el);
const titleEl = article.find('h2.blog-title a, h2 a, h3 a').first();
const title = titleEl.text().trim();
const link = titleEl.attr('href');
const snippet = article.find('.news-image p, p').first().text().trim();
const date = article.find('.tc-blogpost-date, .entry-meta').first().text().trim().replace(/\s+/g, ' ');
const image = article.find('img.wp-post-image, img').first().attr('src') || null;
const categories = [];
article.find('.post-categories li a, .tc-blog-cats a').each((_, c) => {
const cat = $(c).text().trim();
if (cat && !categories.includes(cat)) categories.push(cat);
});
if (title && link) {
items.push({
title,
link,
snippet: snippet || null,
date: date || null,
image,
categories
});
}
});
return {
status: true,
type: query ? 'search' : 'latest',
query: query || 'latest_corporate',
page: Number(page) || 1,
total: items.length,
result: items
};
}
// CLI runner
if (require.main === module) {
const input = process.argv[2] || 'cloud';
const page = process.argv[3] || 1;
tencentScraper(input, page)
.then(res => {
console.log(JSON.stringify(res, null, 2));
})
.catch(err => {
console.error(JSON.stringify({ status: false, error: err.message }, null, 2));
process.exit(1);
});
}
module.exports = {
tencentScraper
};