Fundamentals 5 min read

How to Open a Web Page with Python: os.system, Selenium, and webbrowser

The article examines how viral “hacker” videos misuse simple batch commands, then explains three practical Python methods—using os.system, Selenium WebDriver, and the built‑in webbrowser module—to reliably open a URL, comparing their capabilities and providing sample code.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How to Open a Web Page with Python: os.system, Selenium, and webbrowser

While scrolling through short videos on social platforms, many so‑called “hacker” clips show a few lines of batch commands that appear impressive but actually just open a web page. The most common pattern uses dir/s, start, exit, do and loop. The start command launches an executable or a BAT script and runs it in parallel, which is why it is often used to open multiple instances of applications such as the desktop version of WeChat.

Using the os module

By importing the built‑in os module, you can call the system’s default browser via os.system. Replace the placeholder path and URL with your own values.

import os

os.system('"C:/.../chrome.exe" https://cybermap.kaspersky.com/')

Using selenium

The selenium package allows you to launch a browser and automate any interaction, which is useful for testing, crawling, or filling forms.

from selenium import webdriver

driver = webdriver.Chrome(your_browser_path)
driver.get("https://cybermap.kaspersky.com/")

After opening the page, you can continue to click buttons, fill forms, scroll, etc., using Selenium’s API.

Using the built‑in webbrowser module

The webbrowser module is part of the Python standard library and simply opens the system’s default browser.

python -m webbrowser -t "https://cybermap.kaspersky.com/"

Command‑line options:

-n : open a new window

-t : open a new tab

In code, the module provides three main functions:

webbrowser.open(url, new=0, autoraise=True)
webbrowser.open_new(url)
webbrowser.open_new_tab(url)

The new argument controls how the page is opened:

new=1 : open in a new browser window

new=2 : open in a new tab

Choose webbrowser for simple URL opening. If you need to simulate user actions, Selenium is more appropriate. For advanced automation that combines simple opening with UI interaction, you can pair webbrowser with modules like pyautogui to perform clicks and keystrokes.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonTutorialSeleniumWeb Automationos.systemwebbrowser
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.