Last active
November 10, 2017 01:41
-
-
Save pezy/e782e141caf714e50cece01a4f4d3d4d to your computer and use it in GitHub Desktop.
Extract the chapter list from oreilly book website
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, '`<'); | |
content = content.replace(/>/g, '>`'); | |
document.write('> Q: ' + content + '<br>'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment