Skip to content

Instantly share code, notes, and snippets.

@pezy
Last active November 10, 2017 01:41
Show Gist options
  • Save pezy/e782e141caf714e50cece01a4f4d3d4d to your computer and use it in GitHub Desktop.
Save pezy/e782e141caf714e50cece01a4f4d3d4d to your computer and use it in GitHub Desktop.
Extract the chapter list from oreilly book website
var chapter_list = document.getElementsByClassName('chapter');
var result = [];
for (var i = 0; i < chapter_list.length; ++i)
result.push(chapter_list[i].getElementsByTagName('h3')[0].innerText);
for (var i = 0; i < result.length; ++i)
document.write('- [ ] '+ result[i] + '<br>');
var bodies = document.getElementsByClassName('calibre16')
var body = bodies[bodies.length - 1]
var questions = body.getElementsByClassName('calibre21')
document.write('# ' + document.getElementsByClassName('entry-title')[0].innerText + '<br><br>')
for (var i = 1; i < questions.length; i += 2) {
var item = questions.item(i);
var content = item.getElementsByTagName('p')[0].innerText;
content = content.replace(/</g, '`&lt');
content = content.replace(/>/g, '&gt`');
document.write('> Q: ' + content + '<br>');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment