From b31d4edd720ccbe73c41524443cff2aad99e9e63 Mon Sep 17 00:00:00 2001 From: "Dewa M. Widyakumara" Date: Sun, 21 Apr 2019 16:52:05 +0700 Subject: [PATCH] add: instagram/tag (#1964) add support to fetch instagram's hashtags. eg: * [#designertoys](https://www.instagram.com/explore/tags/designertoys/) * [#urbantoys](https://www.instagram.com/explore/tags/urbantoys/) --- docs/en/README.md | 2 + lib/router.js | 1 + lib/routes/instagram/tag.js | 109 ++++++++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 lib/routes/instagram/tag.js diff --git a/docs/en/README.md b/docs/en/README.md index 0767e2c12f..25f20367c3 100644 --- a/docs/en/README.md +++ b/docs/en/README.md @@ -225,6 +225,8 @@ If no matching results were found, the server returns only a HTTP status code `2 + + ### Youtube diff --git a/lib/router.js b/lib/router.js index 3bf2652937..4f7aee8c71 100755 --- a/lib/router.js +++ b/lib/router.js @@ -258,6 +258,7 @@ if (config.twitter && config.twitter.consumer_key && config.twitter.consumer_sec // Instagram router.get('/instagram/user/:id', require('./routes/instagram/user')); +router.get('/instagram/tag/:tag', require('./routes/instagram/tag')); // Youtube if (config.youtube && config.youtube.key) { diff --git a/lib/routes/instagram/tag.js b/lib/routes/instagram/tag.js new file mode 100644 index 0000000000..6e7bd29954 --- /dev/null +++ b/lib/routes/instagram/tag.js @@ -0,0 +1,109 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const tag = ctx.params.tag; + + const response = await axios({ + method: 'get', + url: `https://www.instagram.com/explore/tags/${tag}/`, + headers: { + Referer: `https://www.instagram.com/explore/tags/${tag}/`, + }, + }); + + const data = JSON.parse(response.data.match(/