Advertisement
metalx1000

Scrape Flash Card Data

Jan 16th, 2025 (edited)
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const textarea = document.createElement("textarea");
  2. textarea.rows = 50;
  3. textarea.style.width = "100%";
  4.  
  5. //Put the Text Area at the top of the page
  6. document.querySelector('body').prepend(textarea);
  7.  
  8. // Loop through Each Flash Card
  9. let timer = setInterval(() => {
  10.   let next = document.querySelector('[aria-label="arrow right"]');
  11.  
  12.   // If Next Button does not exist the clear timer and exit
  13.   if (next === null) {
  14.     clearInterval(timer);
  15.     return;
  16.   }
  17.  
  18.   // get flash card values and add them to the text area output
  19.     //Replace New lines with <br> tag
  20.   let card = document.querySelectorAll('[data-testid="Card"]');
  21.   let question = card[0].children[0].children[2].innerText;
  22.     question = question.replace(/(?:\r\n|\r|\n)/g, '<br>');
  23.   let answer = card[1].children[0].children[2].innerText;
  24.     answer = answer.replace(/(?:\r\n|\r|\n)/g, '<br>');
  25.   textarea.value += `<div class='questions'>${question}<hr><div class='answers'>${answer}</div></div>\n`;
  26.  
  27.   //Click The Next Button
  28.   let button = next.parentElement;
  29.   button.click();
  30. }, 200);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement