Created
November 18, 2020 17:22
-
-
Save theabbie/a2dc2b70bef755161c6cc2f8b1a1e598 to your computer and use it in GitHub Desktop.
URL unshortener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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