Thursday, January 19, 2012

Python Script to Open Webpages in Firefox tabs (or any browser supported by the python webbrowser library)

  #python  
import webbrowser  
a = ['http://www.google.com/reader','http://www.yahoo.com/','http://www.facebook.com/']  
  for x in a:  
       webbrowser.get('firefox').open_new_tab(x)  

You just need to copy and paste that code into a text file and save it as something like "opensite.py" (better to use the .py extension)

Make it executable running the following command in terminal:
 sudo chmod a+x opensite.py  

Run it either in the command line with
 python /path/to/opensite.py  

Or create a launcher (you can do this in Ubuntu easily by right clicking on the desktop)

4 comments:

  1. hi man. i would realy apreciate if you can tell me what is the problem with this script what it supose to do is to request a webpage in regular intervals without using a browser ty man..

    import urllib #isxoroume stin vivliothiki urllib

    import time #ishoroume stin vivliothiki time (gia na rithmisoume to w8 time pou tha trexei )
    link = ('http://forfreeprogram.blogspot.gr/','')
    #mesa sta komma vazoume ta link pou theloume na kanei request
    link_pos = 0
    request_count = 1

    while True:
    try:
    if request_count == 2:

    link_pos = link_pos + 1

    request_count = 0

    request_count = request_count + 1

    time.sleep(480)

    urllib2.urlopen(link_pos) #afti i entoli kanei request to link

    except:

    pass
    else:

    pass

    ReplyDelete
    Replies
    1. I would but I'm not very good at debugging... Try http://stackoverflow.com/

      Delete
    2. actually the program is runing but is not doing what is suposed to do... a cyber friend of a friend of mine rote this code... you think you can make somthing similar to this and we can try it and benefit as bolth i have a sertain way i am gonna use it ;)

      Delete
  2. This comment has been removed by the author.

    ReplyDelete