Monday 15 July 2013

python - Automatic webbrowser opening/closing issue -



python - Automatic webbrowser opening/closing issue -

i've written python script running on windows 32bit machine query mysql database , proceed open webbrowser relevant url , after 15 seconds terminate in rough way browser process , each entry in result set.

is there nicer way load page, wait page load , close browser instead of using time.sleep() , terminating browser process crudely?

import webbrowser,time,subprocess,pymysql # open db connection db = pymysql.connect(host="localhost", user="dev", passwd="password", db="testdb") # create cursor , execure sql statement cursor = db.cursor() cursor.execute("select name, id test_table") # commit changes if db.commit() # number of rows in resultset numrows = int(cursor.rowcount) # loop through resultset x in range(0, numrows): row = cursor.fetchone() url = '' if (row[1] == 1): url = 'http://localhost/?name=' + row[0] if (row[1] == 2): url = 'http://localhost/?func=2&name=' + row[0] webbrowser.open_new(url) time.sleep(15) subprocess.call("taskkill /im iexplore.exe /f /t", shell=true) time.sleep(15) cursor.close() db.close()

python python-2.7 browser

No comments:

Post a Comment