CodeF53/bing-image-scraper

a scraper for bing.com/images

★ 1Forks 0TypeScriptGitHub ↗Compare

README

@f53/bing-image-scraper

This work is licensed under CC BY-SA 4.0. To view a copy of this license, visit https://creativecommons.org/licenses/by-sa/4.0/

Example usage:

import { bingImages } from '@f53/bing-image-scraper'

const results = await bingImages('miiverse yeah!')
if (Error.isError(results)) {
  console.error(results)
}
else {
  console.log(results[1]) // => {
  //   thumbnail: "https://ts2.mm.bing.net/th?id=OIP.kpe_hK2VB0dOEQLIth9-WAHaC7&pid=15.1",
  //   source: "https://danbooru.donmai.us/posts?tags=miiverse_yeah!_(meme)",
  //   direct: "https://cdn.donmai.us/original/92/97/9297bf84ad9507474e1102c8b61f7e58.jpg",
  //   description: "Miiverse Yeah! (Meme) | Danbooru",
  //   title: "Miiverse Yeah! (Meme) | Danbooru",
  // }
}

bingImages returns a Promise<Error | Array<BingImg>

type BingImg = Record<'thumbnail' | 'source' | 'direct' | 'description' | 'title', string>

bingImages takes an optional Partial<BingScrapeOptions>

interface BingScrapeOptions {
  userAgent: string
  language: string
}

You can change the language you get your results in or use a newer userAgent by setting your BingScrapeOptions:

const results = await bingImages('brunost', {
  userAgent: '...', // https://www.whatismybrowser.com/guides/the-latest-user-agent/chrome
  language: 'nb-NO,no;q=0.5'
})

Contributors

CodeF53

Issues