I'm trying to write a python script on windows platform to open a webpage(such as Google), and then, after 10 seconds, close this website.
Note: I'm using Windows 7, Python 2.7.10, and IE
To open a page in a specific browser, use the webbrowser. get() function to specify a particular browser.
It is functional for all browsers, works on all major OS and its scripts are written in various languages i.e Python, Java, C#, etc, we will be working with Python. The close() method is a web driver command which closes the browser window.
Use webbrowser. open() to open a website open(url, new=1) to open the url in the default web browser of the system. new=1 opens a new browser window, new=0 opens in the same browser window, and new=2 opens in a new tab.
Click on the "X" button in the upper-right corner of the browser window to close it. You can also click "File" in the upper-left corner and then choose "Exit" to close the browser. For an alternate method, push "Alt" and "F4" simultaneously to close the browser using a Windows shortcut.
You can use pythons built in webbrowser module to open the default browser:
import webbrowser
webbrowser.open("http://google.co.uk")
https://docs.python.org/2/library/webbrowser.html
If you want more control of the browser (for example the ability to close the browser) you could investigate the use of Selenium, however I believe you have to be specific about what browser to open.
from selenium import webdriver
from time import sleep
driver = webdriver.Firefox()
driver.get("http://google.co.uk")
sleep(10)
driver.close()
http://selenium-python.readthedocs.org/en/latest/getting-started.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With