4

Consider a jupyter notebook that's installed on a remote server on port 8888. Suppose this remote server has also a web server on port 80. Consider also the port 8888 is exposed to the public, but the port 80 not, it's accessible only from the localhost (where the jupyter notebook is running). Is there a way to navigate this local web server from a jupyter notebook opened in my local web browser?

I tried to find some solutions on stackoverflow, but I can't find something that's suitable for my situation.

I found a lot of stuffs like using IFrame from IPython.display, also something like using urlopen stuffs, but it not works as I expected, I can't navigate in the web server as we do in a standard web browser. I think I need something like a port forward, or a proxy, or a tunnel implemented in python that works in a jupyter notebook.

from six.moves.urllib.request import urlopen
url='http://localhost:80'
response = urlopen(url)
content = str(response.read())

from IPython.core.display import display, HTML
display(HTML(content))

It prints the HTML in the jupyter notebook, but we could not navigate as expected like using:

from IPython.display import IFrame

url = 'https://www.wikipedia.org'
IFrame(url, width=800, height=400)

Some suggestions?

1 Answers1

2

You can present arbitrary HTML within your notebook.

In response to your comment, could you request the page via a standard GET, and present it through the IPython HTML tag?

As the request will perform locally, the notebook can fetch the content. Depending upon the page complexity (static asset paths for example) it'll render html:

import requests
content = requests.get('https://localhost:80/').text
from IPython.display import HTML, display
display(HTML(content))

As an alternative could be a simple proxy such as https://ngrok.com/


Create a standard HTML hyperlink in your code:

from IPython.display import HTML, display
display(HTML("<a target='_blank' href='https://google.com'>google</a>"))

Alternatively a markdown block allows standard HTML tags to add the same <a> hyperlink.

Glycerine
  • 7,157
  • 4
  • 39
  • 65