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

Scraper pixiv

Scraper pixiv

#github-gist#javascript#gist:495856ebe5c0446f3ac14732492c55da#gistsync:2026-09-02T12:40:38Z
0
Raw
pixiv.jsjavascript
74 lines
1
2
3import * as __ns_727 from 'node:url'
4const pathToFileURL = __ns_727.pathToFileURL
5
6const PIXIV_BASE = "www.pixiv.net";
7const HEADERS = {
8 "User-Agent": "Mozilla/5.0 (Linux; Android 12; Pixel 6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36",
9 Referer: "https://www.pixiv.net/",
10 Accept: "application/json",
11 "Accept-Language": "en-US,en;q=0.9",
12};
13
14async function pixivSearch(tag, options = {}) {
15 const lang = options.lang || 'en';
16 const apiUrl = `https://${PIXIV_BASE}/touch/ajax/tag_portal?word=${encodeURIComponent(tag)}&lang=${lang}`;
17
18 try {
19 const res = await fetch(apiUrl, { headers: HEADERS });
20 if (!res.ok) throw new Error(`HTTP Error: ${res.status}`);
21
22 const json = await res.json();
23 if (json.error) throw new Error(json.message || "Pixiv Error");
24
25 return {
26 status: true,
27 body: json.body
28 };
29 } catch (e) {
30 return { status: false, error: e.message };
31 }
32}
33
34if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
35 const __exports = { pixivSearch: pixivSearch }
36 const __fns = Object.fromEntries(Object.entries(__exports).filter(([, v]) => typeof v === 'function'))
37 const __names = Object.keys(__fns)
38 if (__names.length === 0) {
39 console.log('Tidak ada fungsi yang bisa di-demo. Import modul ini dari kode lain.')
40 } else {
41 const __search = __names.find((n) => /search|cari/i.test(n))
42 const __name = __search || __names[0]
43 const __fn = __fns[__name]
44 const __isClass = /^class\s/.test(Function.prototype.toString.call(__fn))
45 const __defaultArgs = (() => {
46 const n = __name.toLowerCase()
47 if (/emoji/.test(n)) return [{ emoji: '๐Ÿ˜€๐Ÿ˜ƒ' }]
48 if (/textpro|generate.*text|effect/.test(n)) return ['neon', 'Hello']
49 if (/image|wallpaper|search|query|anime|movie|manga|news|lyrics|wiki|quote|stalk|detail/.test(n)) return ['naruto']
50 if (/download|youtube|video|audio|music|spotify|tiktok|instagram|facebook|twitter|reels|terabox|media/.test(n)) return ['https://www.youtube.com/watch?v=dQw4w9WgXcQ']
51 if (/dork/.test(n)) return ['example.com', 'documents']
52 if (/tts|speech|prompt|chat|ask|translate/.test(n)) return ['Hello world']
53 if (/parse|format|normalize|list|features/.test(n)) return []
54 return ['test']
55 })()
56 let __args = __defaultArgs
57 if (process.argv.length > 2) __args = process.argv.slice(2).map((a) => { try { return JSON.parse(a) } catch { return a } })
58 if (__args.length === 0 && !__search && !__isClass && __fn.length > 0) {
59 console.log('Fungsi: ' + __names.join(', '))
60 console.log('Contoh: node ' + "pixiv.js" + ' ' + __name + ' <arg>')
61 } else {
62 ;(async () => {
63 try {
64 const r = __isClass ? new __fn(...__args) : await __fn(...__args)
65 console.log(JSON.stringify(r, null, 2))
66 } catch (e) {
67 console.error('Error: ' + (e && e.message ? e.message : e))
68 process.exitCode = 1
69 }
70 })()
71 }
72 }
73}
74
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.