bing.mjs
javascript•Created 30 Nov 2025, 08:44•101 views
Simple search for articles, images, and videos on Bing.
#search#tools#utility
javascript
0 lines
/***
@ Base: https://www.bing.com/
@ Author: Shannz
@ Desc: Simple search for articles, images, and videos on Bing.
***/
import axios from 'axios';
import * as 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();
let link = $(element).find('a').attr('href');
if (link) {
if (!link.startsWith('http')) {
link = link.startsWith('/')
? `https://www.bing.com${link}`
: `https://www.bing.com/${link}`;
}
} else {
link = '';
}
videoDetails.push({
title,
duration,
views,
uploadDate,
channel,
link: link
});
});
return videoDetails;
} catch (error) {
console.error('Error fetching video details:', error);
}
}
};
/*
(async () => {
// Search Web
console.log("Searching Website...");
const w = await bing.search('kitsulabs shannz');
console.log("Result Search Web:", w);
// Search images
console.log("Searching Images...");
const i = await bing.images('tokosaki kurumi');
console.log("Result Search Image:", i);
// Search Videos
console.log("Searching Videos...");
const v = await bing.videos('date a live s1 e5');
console.log("Result Search Video:", v);
})();
*/