Skip to content

Instantly share code, notes, and snippets.

@theabbie
Created November 18, 2020 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theabbie/a2dc2b70bef755161c6cc2f8b1a1e598 to your computer and use it in GitHub Desktop.
Save theabbie/a2dc2b70bef755161c6cc2f8b1a1e598 to your computer and use it in GitHub Desktop.
URL unshortener
var axios = require("axios");
var cheerio = require("cheerio");
async function unshorten(url) {
var page = await axios({
url: "https://unshorten.it/",
withCredentials: true
});
var $ = cheerio.load(page.data);
var token = $("input[name='csrfmiddlewaretoken']")[0].attribs.value;
var cookies = page.headers["set-cookie"].map(x => x.split(";")[0]).join(";");
var lurl = await axios({
url: "https://unshorten.it/main/get_long_url",
method: "POST",
headers: {
'referer': 'https://unshorten.it/',
'accept-encoding': 'application/json',
'cookie': cookies
},
data: 'short-url=' + encodeURIComponent(url) + '&csrfmiddlewaretoken=' + token
});
return lurl.data["long_url"];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment