S
c
R
a
P
e
Edit Snippet
Perbarui kode snippet Anda
Judul File
Bahasa
JavaScript
Python
HTML
CSS
JSON
SQL
Bash/Terminal
TypeScript
PHP
Java
Go
Rust
Deskripsi Singkat
(Opsional)
Simple search for articles, images, and videos on Bing
Tags
(Pisahkan dengan koma)
Kode
*
/*** @ Base: https://www.bing.com/ @ Author: Shannz @ Note: Bing search easily and quickly ***/ import axios from 'axios'; import cheerio from 'cheerio'; export const bing = { search: async (query) => { try { const response = await axios.get(`https://www.bing.com/search?q=${query}`); const html = response.data; const $ = cheerio.load(html); const results = []; $('.b_algo').each((index, element) => { const title = $(element).find('h2').text(); const link = $(element).find('a').attr('href'); const snippet = $(element).find('.b_caption p').text(); const image = $(element).find('.cico .rms_iac').attr('data-src'); results.push({ title, link, snippet, image: image ? `https:${image}` : undefined }); }); return results; } catch (error) { console.error('Error fetching data:', error); } }, images: async (query) => { try { const response = await axios.get(`https://www.bing.com/images/search?q=${query}`); const html = response.data; const $ = cheerio.load(html); const url = []; $(".imgpt > a").each((i, el) => { url[i] = $(el).attr("href"); }); const result = []; for (let i = 0; i < url.length; i++) { result[i] = { photo: 'https://www.bing.com' + url[i] }; } return result; } catch (error) { console.error('Error fetching image data:', error); } }, videos: async (query) => { try { const url = `https://www.bing.com/videos/search?q=${query}`; const { data } = await axios.get(url); const $ = cheerio.load(data); const videoDetails = []; $('.mc_vtvc').each((index, element) => { const title = $(element).find('.mc_vtvc_title strong').text(); const duration = $(element).find('.mc_bc_rc.items').first().text(); const views = $(element).find('.meta_vc_content').first().text(); const uploadDate = $(element).find('.meta_pd_content').first().text(); const channel = $(element).find('.mc_vtvc_meta_row_channel').text(); const link = $(element).find('a').attr('href'); videoDetails.push({ title, duration, views, uploadDate, channel, link: `https://www.bing.com${link}` }); }); return videoDetails; } catch (error) { console.error('Error fetching video details:', error); } } };
Monospace
Kunci Admin
*
Update Kode
Batal