Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- base : https://www.google.com/advanced_image_search
- fungsi : buat cari gambar makek search enginie
- google search,
- by : wolep
- update : 21 Juli 2025 11.00 WITA
- note : biasa, single function, 1 param query
- return objek json. easy to use, flexible,
- handle return and error the way you like
- uwu uwu uwu. skrep kalau rusak kasih tau
- gw ya :v atau lu benerin sendiri :v
- nodejs : v24.2.0
- */
- const googleSearchImage = async (query) => {
- if (!query) throw Error(`kata pencarian tidak boleh kosong`)
- const usp = {
- "as_st": "y",
- "as_q": query,
- "as_epq": "",
- "as_oq": "",
- "as_eq": "",
- "imgsz": "l", // image size result. (emptry string = any size) available size : l m i qsvga vga svga xga 2mp 4mp 6mp 8mp 10mp 12mp 15mp 20mp 40mp 70mp
- "imgar": "",
- "imgcolor": "",
- "imgtype": "jpg", // image format (empty sting = any format) available format : jpg gif png bmp svg webp ico craw
- "cr": "",
- "as_sitesearch": "",
- "as_filetype": "",
- "tbs": "",
- "udm": "2"
- }
- const headers = {
- "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"
- }
- const response = await fetch("https://www.google.com/search?" + new URLSearchParams(usp).toString(), {
- headers
- })
- if (!response.ok) throw Error(`gagal hit api ${response.status} ${response.statusText}\n${await response.text() || null}`)
- const html = await response.text()
- const match = html.match(/var m=(.*?);var a=m/)?.[1] || null
- if (!match) throw Error("no match found!")
- const json = JSON.parse(match)
- const images = Object.entries(json).filter(v => v[1]?.[1]?.[3]?.[0]).map(v =>
- ({
- title: v[1]?.[1]?.[25]?.[2003]?.[3] || null,
- imageUrl: v[1][1][3][0] || null,
- height: v[1][1][3][1] || null,
- width: v[1][1][3][2] || null,
- imageSize: v[1]?.[1]?.[25]?.[2000]?.[2] || null,
- referer: v[1]?.[1]?.[25]?.[2003]?.[2] || null,
- aboutUrl: v[1]?.[1]?.[25]?.[2003]?.[33] || null
- })
- )
- if (!images.length) throw Error(`hasil pencarian ${query} kosong.`)
- images.pop() // buang element akhir
- return { total: images.length, images }
- }
- // cara pakai
- googleSearchImage("furina fanart")
- .then(console.log)
- .catch(err => console.log(err.message))
- /* output (kalau lu search yang aneh aneh 18+ gitu baru metadatanya lengkap jir, gak null)
- {
- total: 100,
- images: [
- {
- title: null,
- imageUrl: 'https://upload-os-bbs.hoyolab.com/upload/2023/11/26/173296285/c4e9249c76199448936878fb2990dc4f_6233603105822018002.jpg',
- height: 1080,
- width: 764,
- imageSize: null,
- referer: null,
- aboutUrl: null
- }, ... (99 objek lainnya)
- ]
- */
Add Comment
Please, Sign In to add comment