Python Programming for beginners. Pt 3 – Writing .py script for Opening Multiple Websites

Image source : Python logo from python.org (plus I added '3' in image)

By : Bijay Acharya / studentvideotutorial

Hello all and welcome to Part 3 of Python Programming For beginners. Here, I’ll show you the script of Python, which can be used to open multiple websites at once. Main purpose is to simplify our task of daily life.
Before writing scripts, I want to explain something. I use ‘module’ in the script. And, what’s a module ?
Module: To make programming easier, Python has Modules. Modules contain useful code and help in extending Python’s functionality.
Let's begin . . .
Step 1 : Open Python Shell, and open new file (and type)
import webbrowser
In Python, the ‘import’ statement is used to add a module to your project. In this case, we want to add the ‘webbrowser’ module
 Step 2 : Type
webbrowser.open(‘http://site name here’)
Here, we’re calling the open function on our default web browser. We pass it a URL in the form of a string. We can add as many websites as we want. For example:
webbrowser.open(‘http://site name 1 here’)
webbrowser.open(‘http://site name 2 here’)
The final code/script looks like this:
import webbrowser
webbrowser.open(‘http://google.com’)
webbrowser.open(‘http://facebook.com’)
webbrowser.open(‘http://itsolutionpokhara.com’)

Step 3: Save the file as, test.py (test = file name)
Let’s see it in Python Shell and let’s execute test.py
Well this is it :)

Comments