Created
October 20, 2020 15:46
-
-
Save foyez/0026fcecfd56673db91a5ea4ae10e2c6 to your computer and use it in GitHub Desktop.
LightShot Image Extractor: scrapes the jpg screenshot link from a LightShot page
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
const cheerio = require('cheerio') | |
const axios = require('axios') | |
/** | |
* Extracts the jpg url from a LightShot page | |
* lightshot_image('http://prntscr.com/dki21q') | |
* http://image.prntscr.com/image/1aaf571d0adf4aa098eb565bbb196af6.png | |
*/ | |
async function lightshotImageExtractor(url) { | |
try { | |
const { data } = await axios.get(url) | |
const imgUrl = parseHTML(data) | |
return imgUrl | |
} catch (err) { | |
console.log(err) | |
return null | |
} | |
} | |
function parseHTML(html) { | |
const $ = cheerio.load(html) | |
const rows = $('.screenshot-image') | |
if (rows.length > 0 && rows[0].attribs && rows[0].attribs.src) { | |
return rows[0].attribs.src | |
} | |
return null | |
} | |
lightshotImageExtractor('http://prntscr.com/dki21q').then((url) => | |
console.log(url), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment