Sunday, 15 August 2010

google chrome - How to open a newtab page using the webbrowser module in python? -


I am currently trying to open my Chrome default new tab page using the Web Browser Module in Python. I have worked to create random URLs while trying this as URL: // NewTab, I only get a message that "there are no apps installed to open this type of link".

Here is the relevant bit of code (no more):

  Import Webbrover Webbrover. Open_NU_Teb ("chrome: // newtab")  

Yes, Chrome is my default browser, thanks for the help!

Note that states:

Note that on some platforms , Trying to open a file name using this function, the operating system's associated program can start and work. However, it is neither supported nor portable.

It's been a while since I saw it, but my memory is that at least some systems, the way it works under the hood, Designed in the system, which opens the URI in any type of system system of URI. In other words, the default application is used for the given file type. It does not matter whether the URI indicates the local file or not. Therefore, the URI http: //examplce.comn/somefile.pdf can open the PDF file on the system default PDF viewer, which can not be a browser as a documentation note, due to the underlying implementation of the crash Works from

However, in a separate OS, such system specific order is not present, and all URIs will be opened in the web browser.

You have failed to mention the OS that you are working on (and I can forget which OS works), but I suspect that you are on the first type of OS Are working.

You may be may (depending on your system again) using a specific browser to override the default behavior specified.

You use the browser to try the browser as a one-to-store list of environment variable settings to see which characters are used by your system Check the value of (usually ':' os.pathsep ( import os; print os.pathsep )> For posix or ';' for Windows) and then use that character to separate items in the list. Of course, you may only need to assign an item to the list (chrome), in which case you do not have to use the separator at all. In this way (be sure to use the correct path for your system):

  SET BROWSER = "C: \ Program Files (x86) \ Google \ Chrome App \ chrome.exe" / Code>  

Or, you can try the program to choose your browser, however, support for Chrome has not been added unless you are using Python 3.3+ Try:

  Import webbrowser Chrome = webbrowser.get ('google-chrome') # or webbrowser.get ('chrome') chrome.open_new_tab ('Chrome: // newtab')  

Note: A Rokt has not been tested. I do not know which system you have and so I am not able to replicate your specific setup. YMMV

Update:

As I now know that you are on a pre-Python 3.3 window machine, maybe the following will help. You can also register a browser so that Python is aware of it:

  p: \ program files (x86) \ Google \ Chrome \ app \ chrome.exe "webbrowser.register ( 'Chrome', None, Web Browser. Backfloor Browser (Peth) chrome = webbrowser.get chrome.open_new_tab ('chrome: // newtab')  

No comments:

Post a Comment