Back to Home
Gistify Snippet
kyiov
Sep 3ยท1 file(s)
Public

Scraper reels-search

Scraper reels-search

#github-gist#javascript#gist:ae54f77df2ae3154fbefac6e0516eae4#gistsync:2026-09-02T12:40:32Z
1
Raw
reels-search.jsjavascript
109 lines
1
2
3import * as __ns_321 from 'axios'
4const axios = __ns_321.default
5import * as __ns_322 from 'node:url'
6const pathToFileURL = __ns_322.pathToFileURL
7
8async function reelsSearch(query, num = 10) {
9 try {
10 const cx = "e500c3a7a523b49df";
11
12 const ins = axios.create({
13 headers: {
14 'user-agent': 'Mozilla/5.0 (Linux; Android 16; SM-F966B Build) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Mobile Safari/537.36',
15 'x-client-data': 'CJDjygE='
16 }
17 });
18
19 const { data: init } = await ins.get("https://cse.google.com/cse.js", { params: { cx: cx } });
20
21 const cfg_ = init.match(/}\)\(({[\s\S]*?})\);/);
22 if (!cfg_ || !cfg_?.[1]) throw new Error("Failed to find config");
23 const cfg = JSON.parse(cfg_[1]);
24
25 const params = {
26 rsz: 'filtered_cse',
27 num,
28 hl: 'id',
29 source: 'gcsc',
30 cselibv: cfg.cselibVersion,
31 cx: cx,
32 q: query,
33 safe: 'off',
34 cse_tok: cfg.cse_token,
35 lr: '',
36 cr: '',
37 gl: 'id',
38 filter: 0,
39 sort: '',
40 as_oq: '',
41 as_sitesearch: '',
42 exp: 'cc,apo',
43 oq: '',
44 callback: 'google.search.cse.api11171',
45 rurl: Buffer.from("aHR0cHM6Ly9yZWVsc2ZpbmRlci5zYXRpc2h5YWRhdi5jb20v", "base64").toString()
46 };
47
48 let ab = await ins.get('https://cse.google.com/cse/element/v1', {
49 params,
50 }).then(response => response.data);
51
52 const jsonStartIndex = ab.indexOf('{');
53 const jsonEndIndex = ab.lastIndexOf('}');
54 const jsonString = ab.slice(jsonStartIndex, jsonEndIndex + 1);
55
56 const jsonData = JSON.parse(jsonString);
57
58 return jsonData.results.map(item => ({
59 title: item.richSnippet?.metatags?.ogTitle || item.title,
60 description: item.richSnippet?.metatags?.ogDescription || item.snippet,
61 url: item.url,
62 image: item.richSnippet?.metatags?.ogImage || (item.pagemap?.cse_image?.[0]?.src)
63 }));
64 } catch(e) {
65 throw e;
66 }
67}
68
69if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
70 const __exports = { reelsSearch: reelsSearch }
71 const __fns = Object.fromEntries(Object.entries(__exports).filter(([, v]) => typeof v === 'function'))
72 const __names = Object.keys(__fns)
73 if (__names.length === 0) {
74 console.log('Tidak ada fungsi yang bisa di-demo. Import modul ini dari kode lain.')
75 } else {
76 const __search = __names.find((n) => /search|cari/i.test(n))
77 const __name = __search || __names[0]
78 const __fn = __fns[__name]
79 const __isClass = /^class\s/.test(Function.prototype.toString.call(__fn))
80 const __defaultArgs = (() => {
81 const n = __name.toLowerCase()
82 if (/emoji/.test(n)) return [{ emoji: '๐Ÿ˜€๐Ÿ˜ƒ' }]
83 if (/textpro|generate.*text|effect/.test(n)) return ['neon', 'Hello']
84 if (/image|wallpaper|search|query|anime|movie|manga|news|lyrics|wiki|quote|stalk|detail/.test(n)) return ['naruto']
85 if (/download|youtube|video|audio|music|spotify|tiktok|instagram|facebook|twitter|reels|terabox|media/.test(n)) return ['https://www.youtube.com/watch?v=dQw4w9WgXcQ']
86 if (/dork/.test(n)) return ['example.com', 'documents']
87 if (/tts|speech|prompt|chat|ask|translate/.test(n)) return ['Hello world']
88 if (/parse|format|normalize|list|features/.test(n)) return []
89 return ['test']
90 })()
91 let __args = __defaultArgs
92 if (process.argv.length > 2) __args = process.argv.slice(2).map((a) => { try { return JSON.parse(a) } catch { return a } })
93 if (__args.length === 0 && !__search && !__isClass && __fn.length > 0) {
94 console.log('Fungsi: ' + __names.join(', '))
95 console.log('Contoh: node ' + "reels-search.js" + ' ' + __name + ' <arg>')
96 } else {
97 ;(async () => {
98 try {
99 const r = __isClass ? new __fn(...__args) : await __fn(...__args)
100 console.log(JSON.stringify(r, null, 2))
101 } catch (e) {
102 console.error('Error: ' + (e && e.message ? e.message : e))
103 process.exitCode = 1
104 }
105 })()
106 }
107 }
108}
109
Discussion & Comments0

No comments yet โ€” be the first to leave feedback or start a code discussion.

Sign in with your GitHub account to write comments and join the discussion.