Show DevBest [PY] Web Browser?

Sway

Ruby and Python are married.
Dec 19, 2010
194
76
I have no idea what to name this but you pretty much enter the website you want to go to (through the command line) and it will open your default browser and take you to that website.

Source:


Source 2:


Source 3:


Source 4 and final:


Snippet:
Code:
def main():
    print()
    print("Do not add 'http://'")
    website = input("Website: ")
 
    print("Opening website...")
    time.sleep(2)
    webbrowser.open_new("http://%s" % website)
 
    startOver()

It was created in Python in roughly 15 minutes. Was experimenting with the webbrowser module. I will add other options like opening the website in a new tab or choosing a browser of your choice.

FAQ:
Q) Couldn't I just open my browser and go to the website, instead of spending more time using this?

A) This is mainly for educational purposes. I have no idea why you would use this over a real browser yet.. however I'm sure there is a good use. Still learning about the webbrowser module.
 

Sway

Ruby and Python are married.
Dec 19, 2010
194
76
Thanks.

UPDATE:
** Added the option to open in a new tab or in a new window (current window if availabe).

Source:


Snippet:
Code:
def main():
    print()
    print("Do not add 'http://'")
    website = input("Website: ")
    choice = input("Do you wish to open it in a new tab [NT] or seperate window [W]? ")
 
    if choice.lower() == 'w': 
        print("Opening website in new window...")
        time.sleep(2)
       
        webbrowser.open_new("http://%s" % website) 
        startOver()
    elif choice.lower() == 'nt':
        print("Opening website in new tab...")
        time.sleep(2)
       
        webbrowser.open_new_tab("http://%s" % website) 
        startOver()
    else:
        print("I didn't get that..")
        startOver()
 

Sway

Ruby and Python are married.
Dec 19, 2010
194
76
Thanks.

UPDATE:
** Added the option to choose the browser of your choice. This browser must be in your PATH.

You can use the following aslong as they are in your PATH.

35ba1yp.png


Using 'windows-default' will load up your favorite or default browser.

Source:


Snippet:
Code:
def main():
    print()
    print("Do not add 'http://'")
    website = input("Website: ")
    print()
    browsers = input("View the list of browsers? [Y / N]: ")
    if browsers.lower() == "y":
        print()
        print('''You can use: 'windows-default' to load the default (favorite) browser.
You can use any other name aslong as that browser is in your PATH.''')
        print()
 
    browserChoice = input("Browser (use 'windows-default' for the default browser): ")
                         
    choice = input("Do you wish to open it in a new tab [NT] or seperate window [W]? ")
 
    if choice.lower() == 'w':
        print("Opening website in new window...")
        time.sleep(2)
 
        browser = webbrowser.get(browserChoice)
        webbrowser.open_new("http://%s" % website) 
        startOver()
           
    elif choice.lower() == 'nt':
        print("Opening website in new tab...")
        time.sleep(2)
 
        browser = webbrowser.get(browserChoice)
        webbrowser.open_new_tab("http://%s" % website) 
        startOver()
    else:
        print("I didn't get that..")
        startOver()

It took about an hour to create in Python. This is pretty much it for this script. The next update will feature exception handlers and then that will be the final release.
 

Sway

Ruby and Python are married.
Dec 19, 2010
194
76
UPDATE:
** Added exception handlers.

Source:


Snippet:
Code:
def main():
    print()
    print("Do not add 'http://'")
    website = input("Website: ")
    print()
    browsers = input("View the list of browsers? ")
    if any(browsers.lower() in choice_yes for choices_yes in browsers.lower()):
        print()
        print('''You can use: 'windows-default' to load the default (favorite) browser.
You can use any other name aslong as that browser is in your PATH.''')
        print()
 
    browserChoice = input("Browser (use 'windows-default' for the default browser): ")
                         
    choice = input("Do you wish to open it in a new tab [NT] or seperate window [W]? ")
 
    if choice.lower() == 'w':
        print()
        print("Opening website in new window...")
        time.sleep(2)
       
        try:
            browser = webbrowser.get(browserChoice)
            webbrowser.open_new("http://%s" % website) 
        except webbrowser.Error:
            print()
            print("Invalid browser!")
            startOver()
        else:
            startOver()
           
    elif choice.lower() == 'nt':
        print()
        print("Opening website in new tab...")
        time.sleep(2)
 
        try:
            browser = webbrowser.get(browserChoice)
            webbrowser.open_new_tab("http://%s" % website) 
        except webbrowser.Error:
            print()
            print("Invalid browser!")
            startOver()
        else:
            startOver()
           
    else:
        print("I didn't get that..")
        startOver()

This is the final update and release of this script. To run it, you must have Python installed.
 

Users who are viewing this thread

Top