Guest User

Comments Extraction Script (by pie42)

a guest
Jan 1st, 2023
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (async ()=>{let id = 0, comments = [], t_id = 929679, nComments = 5; /* note that comments are fetched in sets of 4, so you'll get nComments * 4 back*/
  2. let reverse = true;
  3. let loadMore = true;
  4. for (let i = 0; i < nComments; i++) {
  5.     await fetch(`https://www.freeriderhd.com/track_comments/load_more/${t_id}/${id}`, {method: 'POST'}).then(i=>i.json()).then(i=>{comments.push(...i.data.track_comments); loadMore = i.data.track_comments_load_more});
  6.     id = comments[comments.length - 1].comment.id;
  7.     if (!loadMore) break;
  8. }
  9. if (reverse) comments = comments.reverse();
  10. let formatted = comments.map(i=>`${i.user.d_name} (${i.comment.time}): ${i.comment.msg.replaceAll(/\<a href\=\".+?\"\>(.+?)\<\/a\>/g, '@$1')}`).join('\n'),
  11.     parser = new DOMParser(),
  12.     dom = parser.parseFromString(
  13.         '<!doctype html><body>' + formatted,
  14.         'text/html'
  15.     ),
  16.     corrected = dom.body.textContent;
  17. console.log(corrected)})()
Advertisement
Add Comment
Please, Sign In to add comment