This aim of this session is to for you to learn how to open a website, or a specific web page, in a browser using Python code.
Opening a website in a browser can be useful. At the end of this session you will be comfortable with opening any website from within a Python program. This is a skill that we can put to good use later in the course.
You can return here to play and pause the above video should you need to watch it again. Remember that you can watch the videos in full screen mode if you like, click the icon at the bottom right of the video to go to full screen mode, press the Esc key to return to normal windowed mode.
Points To Note
- The library you need to open is the Webbrowser Library
- Use the Open method
- Supply the URL as a string with a prefix of http
- Don’t put this code in a while True loop unless you want lots of tabs opening!
Can you extend this program to provide a menu driven program that opens various websites or specific pages on a site.
Simply give the user a menu and the ability to enter a number representing their choice, then open that website or specific page.
Save your program to the desktop, then double click it to pop up a handy ‘Website Opener’.
You can create different programs for different subjects, eg one for your favourite hobby websites, another one for work.