Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function sleep(ms) {
  2.   return new Promise(resolve => setTimeout(resolve, ms));
  3. }
  4.  
  5. var list = []
  6. var errors = []
  7.  
  8. async function run_page(page) {
  9.   console.log("==PAGE " + page + "==")
  10.  
  11.   let req = await fetch("https://avenoel.org/mes-messages/" + page)
  12.   if (req.status != 200) {
  13.     console.log("Page " + page + "couldn't be fetched")
  14.     errors.push(page)
  15.   }
  16.   let HTMLContent = await req.text()
  17.   if (!HTMLContent.match(/message-permalink/)) {
  18.     return false
  19.   }
  20.   let regex = /href="(https:\/\/image\.noelshack\.com\/fichiers\/.*?)"/g
  21.   let matches = HTMLContent.matchAll(regex)
  22.   let count = 0
  23.   for (match of matches) {
  24.     if (!list.includes(match[1]))
  25.       list.push(match[1])
  26.     count++
  27.   }
  28.   console.log(count + " noelshack URLs found on this page")
  29.  
  30.   return true;
  31. }
  32.  
  33. async function run() {
  34.   var page = 1
  35.   while (await run_page(page)) {
  36.     await sleep(15)
  37.     page++
  38.   }
  39.  
  40.   let res = ""
  41.   for (url of list) {
  42.     res += url + "<br />"
  43.   }
  44.   if (errors.length > 0)
  45.     res += "<br />Those pages couldn't be fetch :<br />"
  46.   for (page of errors) {
  47.     res += ""
  48.   }
  49.  
  50.   document.getElementsByTagName("html")[0].innerHTML = res
  51. }
  52.  
  53. run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement