Home > bash, firefox, python > Open URLs in browser tabs simultaneously

Open URLs in browser tabs simultaneously


From Python, you can easily open URLs in Firefox tabs:

#!/usr/bin/env python

# open_in_tabs.py

import webbrowser
import sys

firefox = webbrowser.get('firefox')

for url in sys.stdin.readlines():
    url = url.rstrip("\n")

This script reads URLs from the standard input and opens them in separated tabs. Usage:

cat url_list.txt | ./open_in_tabs.py

Where url_list.txt contains one URL per line.

It’s all very nice, but… The script will open the URLs one by one, which can be very slow (especially if you want to open several URLs). Would it be possible to open the URLs in tabs at the same time? That is, tell Firefox to assign a thread to each tab and process them simultaneously.


I found the solution in this thread. I won’t provide a source code, just sketch the idea:

  • If Firefox is not running yet, open the first URL with “firefox -new-window URL“. Do it with an external call.
  • For the rest of the URLs, open them with “firefox -new-tab URL“.

Here I suppose you have a running Firefox instance.

cat url_list.txt | while read i; do firefox -new-tab $i; done

Useful links

Related posts

In the post “Extract all links from a web page“, I show an interesting usage of the script open_in_tabs.py. Links of a web page are extracted with another script, and the extracted links are opened in Firefox tabs with open_in_tabs.py. All that is done in one line using pipes. Example:

./get_links.py http://www.beach-hotties.com/ | grep -i jpg | ./open_in_tabs.py

Update (20110507)

The script is updated, now it can open tabs simultaneously too. Also, it can open links in a new window. See the source here.

Categories: bash, firefox, python Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: