I would like to open a new tab in my web browser using python's webbrowser. However, now my browser is brought to the top and I am directly moved to the opened tab. I haven't found any information about this in documentation, but maybe there is some hidden api. Can I open this tab in the possible most unobtrusive way, which means:
not bringing browser to the top if it's minimzed,
not moving me the opened tab (especially if I am at the moment working in other tab - my process is working in the background and it would be very annoying to have suddenly my work interrupted by a new tab)?
On WinXP, at least, it appears that this is not possible (from my tests with IE).
From what I can see, webbrowser is a fairly simple convenience module that creates (probably ) a subprocess-style call to the browser executable.
If you want that sort of granularity you'll have to see if your browser accepts command line arguments to that effect, or exposes that control in some other way.
Related
I'm trying to automate a specific task using python. I need to execute a specific task when a specific colour pops up on the display. For example:
During the automation process, when the code to open a web browser is executed and a web browser pops up,I need to make sure that it actually worked, by detecting the colour at the exact coordinate where the logo of the browser is situated. So that it confirms the browser is open, then I need to use that information to execute another code.
As we know, when we try to open a browser, there will be a lag to open up the browser. Since that lag will be different, I need to execute the next code only after opening the browser.
I have gone too far with my explanation, but if you got any idea from what I have just explained, please help me with what you know?
Im am writing a piece of code where it is vital that the browser stays open however i need to be able to close windows, to stop the browser from over populating. I have been using the webbrowser module but it seems that webbrowser doesnt have a way of close the tab once open. Any ideas?
Remember the browser must stay open, so killing all tabs will close the browser. I must only close the tabs that were opened by my code!
Any help would be greatly appreciated.
Sorry if this isn't in the right place, feel free to move it.
Software:
Python 3.6.4 (32 bit)
Modules used:
Time, Random and Webbrowser.
Webbrowser is a limited api module for interfacing with popular browsers.
The way I see it you have a few options:
Find a module pertaining to the particular browser you're dealing with.
Work with the api of the browser(s) you're working with directly
Request feature of webbrowser in the future, but won't help you now, as they likely won't implement it any time soon.
Essentially what I want to do is be able to click a button and have the webpage state be stored somewhere on the HDD so it doesn't need to just sit in RAM, and when it's loaded again at some later time the page pops up exactly as it was before as if it had never been closed without the need to download anything over the internet to restore it (although additional resource requests that didn't exist when the page was saved should still download properly).
(as an example, firefox does this when it crashes, all the tabs are restored, text you've typed is still in the textboxes, etc..)
I don't care if that button is in a firefox plugin, chrome, or even a custom browser that I program myself with something like webkit perhaps.
I've been trying for days to find a way to do this. I made WebKit programs in both C++ and Python but every time I think I'm getting close there is some deficiency in webkit or a build-in security measure that prevents me from doing this. I tried creating MHTML archives but they don't allow javascript to download new data over the internet, I tried pickling the entire WebKit.WebView object in python, I tried looking through webkit code to see if I could patch the behavior into the source code myself
I'm running out of ideas and the only one I see left is to just post this online. Is there any way that I can do this, in any programming or scripting language, using any libraries at all?
I just have no idea where to turn next.
I've tried asking this question on the KDE development forum, but haven't received a satisfying answer so far.
I've developed a Python script for Amarok 1.4 which retrieves upcoming events for the currently playing artist and displays them in the context browser. The user can click each event to know more about it, but so far clicking takes him to another Amarok tab, in which he must then click another button to finally get the link to open in the external browser.
What I'd like to know is whether there is a way to open the link directly in the external browser.
Update: I recently started using Pana, which actually opens the links directly in the Wikipedia tab, so I guess I'll stick to that player in the future.
I know nothing about Amarok, but in general you can spawn the platform's default web browser on a URL:
on modern open-source desktops (KDE, GNOME, Xfce) by spawning the xdg-open command;
on OS X with the open command;
on Windows with the built-in os.startfile method.
There is also the webbrowser module, but it will often pick the wrong browser and everything about it is outmoded and ugly.
Given this python code:
import webbrowser
webbrowser.open("http://slashdot.org",new=0)
webbrowser.open("http://cnn.com",new=0)
I would expect a browser to open up, load the first website, then load the second website in the same window. However, it opens up in a new window (or new tab depending on which browser I'm using).
Tried on Mac OSX with Safari, Firefox and Chrome and on Ubuntue with Firefox. I'm inclined to believe that new=0 isn't honored. Am I just missing something?
tia,
Note that the documentation specifically avoids guarantees with the language if possible: http://docs.python.org/library/webbrowser.html#webbrowser.open
Most browser settings by default specify tab behavior and will not allow Python to override it. I have seen it in the past using Firefox and tried your example on Chrome to the same effect.
On Windows, it is not possible to specify the tab behavior at all, as suggested by my comment below. The url opening code ignores new:
if sys.platform[:3] == "win":
class WindowsDefault(BaseBrowser):
def open(self, url, new=0, autoraise=True):
try:
os.startfile(url)
I added a delay between successive invocations of webbrowser.open(). Then each was opened in a new tab instead of a separate window (on my Windows 10 machine).
import time
...
time.sleep(0.5)