dylanpurser
dylanpurser

Reputation: 31

Python: Opening and closing IE with a specific URL

I'm currently trying to code a meme generator, and in this I want to load picture memes, have them be open for 10 seconds and then terminate the program (in this case I'm using Internet Explorer). This is how my code looks currently:

import webbrowser
import time
import subprocess

memeURL = "https://image.ibb.co/m9vxqQ/oh_no.jpg"

def open_program(path_name):

    return subprocess.Popen(path_name)

def close_program(p):
    p.terminate()

p = open_program("C:\Program Files\Internet Explorer\iexplore.exe")

time.sleep(10)
close_program(p)

I was wondering if there would be anyway if instead of loading just iexplore.exe, it could load with a url (in this case it would be the variable memeURL). Thanks in advance :)

Upvotes: 0

Views: 288

Answers (1)

Himal
Himal

Reputation: 1371

Just pass the memeURL as an argument to the Popen function.

memeURL = "https://example.com/image.jpg"

def open_program(path_name, url):
    return subprocess.Popen([path_name, url])

p = open_program("C:\Program Files\Internet Explorer\iexplore.exe", memeURL)

Upvotes: 1

Related Questions