https://yadi.sk/i/MkttDiWSVya4L#-*- coding: utf-8 -*-
from xhtml2pdf import pisa
from urllib import urlopen
from time import sleep
menu = ['Introduction/introduction.html', 'AlgorithmAnalysis/analysis.html', 'BasicDS/basic.html', 'BasicDS/stacks.html', 'BasicDS/queues.html', 'BasicDS/deques.html', 'BasicDS/linkedlists.html', 'BasicDS/basic_ex.html', 'Recursion/recursionsimple.html', 'Recursion/graphical.html', 'Recursion/recursioncomplex.html', 'Recursion/recursionexercises.html', 'SortSearch/searching.html', 'SortSearch/sorting.html', 'SortSearch/sortsearchexercises.html', 'Trees/trees.html', 'Trees/implementation.html', 'Trees/bintreeapps.html', 'Trees/heap.html', 'Trees/bst.html', 'Trees/balanced.html', 'Trees/treeexercises.html', 'Graphs/graphintro.html', 'Graphs/graphbfs.html', 'Graphs/graphdfs.html', 'Graphs/graphshortpath.html', 'Graphs/graphexercises.html']
sourceHtml = '''<html><head>
<link rel="stylesheet" href="http://interactivepython.org/courselib/static/pythonds/_static/basic.css" type="text/css" />
<link rel="stylesheet" href="http://interactivepython.org/courselib/static/pythonds/_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="http://interactivepython.org/courselib/static/pythonds/_static/poll.css" type="text/css" />
<link rel="stylesheet" href="http://interactivepython.org/courselib/static/pythonds/_static/tabbedstuff.css" type="text/css" />
<link rel="stylesheet" href="pytutor.css" type="text/css" />
<link rel="stylesheet" href="http://interactivepython.org/courselib/static/pythonds/_static/css/basic.css" type="text/css" />
<link rel="stylesheet" href="codemirror.css" type="text/css" />
<link rel="stylesheet" href="http://interactivepython.org/courselib/static/pythonds/_static/activecode.css" type="text/css" />
<link rel="stylesheet" href="parsons.css" type="text/css" />
<link rel="stylesheet" href="http://interactivepython.org/courselib/static/pythonds/_static/lib/prettify.css" type="text/css" /></head><body>'''
for i in menu:
tmpHtml = urlopen("http://interactivepython.org/courselib/static/pythonds/" + i).read()
tmpHtml = tmpHtml[tmpHtml.find('<div class="container">\n \n <div class="section" id='):tmpHtml.find('<footer class="footer">')]
tmpHtml = tmpHtml.replace('="../', '="http://interactivepython.org/courselib/static/pythonds/')
tmpHtml = tmpHtml.replace('<br/>', '<br>')
sourceHtml += tmpHtml
sleep(10)
sourceHtml += '</body></html>'
pisa.showLogging()
outputFilename = "test.pdf"
resultFile = open(outputFilename, "w+b")
pisaStatus = pisa.CreatePDF(sourceHtml, resultFile)
resultFile.close()
print pisaStatus.err