how to save jupyter notebook as html

Solutions on MaxInterview for how to save jupyter notebook as html by the best coders in the world

showing results for - "how to save jupyter notebook as html"
Ariadna
06 Jan 2017
1from bs4 import BeautifulSoup
2import json
3import urllib.request
4url = 'http://nbviewer.jupyter.org/url/jakevdp.github.com/downloads/notebooks/XKCD_plots.ipynb'
5response = urllib.request.urlopen(url)
6#  for local html file
7# response = open("/Users/note/jupyter/notebook.html")
8text = response.read()
9
10soup = BeautifulSoup(text, 'lxml')
11# see some of the html
12print(soup.div)
13dictionary = {'nbformat': 4, 'nbformat_minor': 1, 'cells': [], 'metadata': {}}
14for d in soup.findAll("div"):
15    if 'class' in d.attrs.keys():
16        for clas in d.attrs["class"]:
17            if clas in ["text_cell_render", "input_area"]:
18                # code cell
19                if clas == "input_area":
20                    cell = {}
21                    cell['metadata'] = {}
22                    cell['outputs'] = []
23                    cell['source'] = [d.get_text()]
24                    cell['execution_count'] = None
25                    cell['cell_type'] = 'code'
26                    dictionary['cells'].append(cell)
27
28                else:
29                    cell = {}
30                    cell['metadata'] = {}
31
32                    cell['source'] = [d.decode_contents()]
33                    cell['cell_type'] = 'markdown'
34                    dictionary['cells'].append(cell)
35open('notebook.ipynb', 'w').write(json.dumps(dictionary))
36
Emely
13 Aug 2016
1from bs4 import BeautifulSoup
2import json
3import urllib.request
4url = 'http://nbviewer.jupyter.org/url/jakevdp.github.com/downloads/notebooks/XKCD_plots.ipynb'
5response = urllib.request.urlopen(url)
6#  for local html file
7# response = open("/Users/note/jupyter/notebook.html")
8text = response.read()
9
10soup = BeautifulSoup(text, 'lxml')
11# see some of the html
12print(soup.div)
13dictionary = {'nbformat': 4, 'nbformat_minor': 1, 'cells': [], 'metadata': {}}
14for d in soup.findAll("div"):
15    if 'class' in d.attrs.keys():
16        for clas in d.attrs["class"]:
17            if clas in ["text_cell_render", "input_area"]:
18                # code cell
19                if clas == "input_area":
20                    cell = {}
21                    cell['metadata'] = {}
22                    cell['outputs'] = []
23                    cell['source'] = [d.get_text()]
24                    cell['execution_count'] = None
25                    cell['cell_type'] = 'code'
26                    dictionary['cells'].append(cell)
27
28                else:
29                    cell = {}
30                    cell['metadata'] = {}
31
32                    cell['source'] = [d.decode_contents()]
33                    cell['cell_type'] = 'markdown'
34                    dictionary['cells'].append(cell)
35open('notebook.ipynb', 'w').write(json.dumps(dictionary))
queries leading to this page
knit to html jupyter notebooksave jupyter notebook with table of contents htmljupyter notebook export to htmlhow to output jupyter notebook as htmljupyter notebook save as html 28with toc 29jupyter notebook output html without codehow to save jupyter notebook as htmlsave jupyter notebook as htmlconvert jupyter notebook to html from notebookcan we write html code in jupyter notebook 3fexport jupyter notebook to htmldisplay html in jupyter notebookimport the output of the jupyter notebook to htmlimport html into jupyter notebookhtml code in jupyter notebookhow to use html in jupyter notebookhow to display html in jupyter notebookhtml to jupyter notebookgenerate thinner html from jupyter notebookconvert html to jupyter notebooksave a jupyter notebook as htmlshow html in jupyter notebookconverting jupyter notebook files to htmlhow to run html code in jupyter notebookjupyter notebook html linkhtml output jupyter notebookhtml jupyter notebookjupyter notebook to html converterjupyter notebook python code in htmlcan you use html in jupyter notebook 3fconvert jupyter notebook to html without codeshow jupyter notebook htmlfrom html to jupyter notebookhow to write html code in jupyter notebookjupyter notebook create htmlsave jupyter notebook as python scriptconvert jupyter notebook to interactive htmljupyter notebook to htmlhow to code html on jupyter notebookconvert jupyter notebook to htmloutput jupyter notebook as htmlhow export html from jupyter notebookcan you do html in jupyterhtml in jupyter notebookview html code jupyter notebookjupyter notebook htmlhow to save jupyter notebook as html