anshulrgoyal / imdb-scrapper

This is small project it provide many good api for search ,scrapping ,trending
39 stars 32 forks source link

Pass headers to a request #25

Closed TheBeastLT closed 5 years ago

TheBeastLT commented 5 years ago

Is it possible to pass some headers for request that are made to imdb? I'd like to pass a language header in order to get titles in specific language like 'accept-language': 'en-GB'

anshulrgoyal commented 5 years ago

you can also use the raw methods provided by the lib.

const {
  getRating,
  getGenre,
  getPro,
  getStory,
  getTitle,
  getRuntime,
  getYear,
  getEpisodeCount,
  getStars,
  getSimilarMoviesById
} = require("imdb-scrapper");
const request=require('request')
function scrapper(id) {
  return request(`${BASE_URL}/title/${id}/?ref_=nv_sr_1`,{headers:{}})
    .then(data => {
      const $ = cheerio.load(data);

      return {
        ...getTitle($),
        ...getRuntime($),
        ...getYear($),
        ...getStory($),
        ...getPro($),
        ...getGenre($),
        ...getRating($),
        ...getPoster($),
        ...getEpisodeCount($),
        ...getSimilarMoviesById($)
      };
    })
    .catch(ifError);
}