Skip to content

Instantly share code, notes, and snippets.

@thuongnn
Created July 30, 2019 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thuongnn/91da024b33b6a7acc20e036f52240204 to your computer and use it in GitHub Desktop.
Save thuongnn/91da024b33b6a7acc20e036f52240204 to your computer and use it in GitHub Desktop.
let content = document.getElementsByClassName("content");
let dataCrawl = localStorage.getItem("dataCrawl") || "";
for (let i = 0; i < content.length; i++) {
let data = content.item(i).childNodes[0];
data.childNodes.forEach(child => {
if (child.className === "qtext") dataCrawl += `\n${child.innerText}`;
if (child.className === "ablock") {
dataCrawl += `\n${child.childNodes[0].firstChild.nodeValue}`;
child.childNodes[1].childNodes.forEach(ans => {
if (ans.childNodes[1]) dataCrawl += `\n${ans.childNodes[1].innerText}`;
});
}
});
if (content.item(i).childNodes[1].childNodes[1]) {
dataCrawl += `\n${content.item(i).childNodes[1].childNodes[1].firstChild.firstChild.nodeValue.replace('The correct answer is:', 'Ans:')}\n`
}
}
localStorage.setItem("dataCrawl", dataCrawl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment