4

Is there any way to open a browser window with a specified URL, then close the browser at a later point?

2 Answers 2

3

Yes, use python's builtin webbrowser module for this.

>>> import webbrowser
>>> url = 'http://www.python.org/'
>>> webbrowser.open_new(url)
Sign up to request clarification or add additional context in comments.

8 Comments

Which opens, but doesn't provide for closing.
You can check this link for other alternatives.
@W00t: Can you please explain the context of your problem as to what you are really trying to achieve by opening and closing browser tabs.
I'm attempting to load a list of sites with a 60 second delay in between, but the sites cannot be open alongside each other.
ok suppose you open 5 pages at a delay of 60 seconds so while closing the webpages you want to close them one by one or all at once.
|
2

The webbrowser module, the easiest way to open a browser window, does not provide a way to close a browser window that it has opened.

For this level of control, try the Selenium module. It's a bit more involved, but offers more control.

Here's an example they give of opening and closing a page:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

browser = webdriver.Firefox()

browser.get('http://www.yahoo.com')
assert 'Yahoo' in browser.title

elem = browser.find_element_by_name('p')  # Find the search box
elem.send_keys('seleniumhq' + Keys.RETURN)

browser.quit()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.