-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserverEdge.py
More file actions
27 lines (25 loc) · 1.01 KB
/
serverEdge.py
File metadata and controls
27 lines (25 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from selenium import webdriver
from subprocess import Popen
from time import sleep
import os
def main():
abspath = os.path.abspath(__file__) # moves to location of script so you don't have to run in folder
dname = os.path.dirname(abspath)
os.chdir(dname)
p = Popen(["python", "-m", "http.server"]) # open the http server
options = webdriver.EdgeOptions()
options.add_experimental_option("excludeSwitches" , ["enable-automation", "enable-logging"])
options.add_argument("--guest")
options.add_argument("start-maximized")
browser = webdriver.Edge(options=options)
browser.get("http://localhost:8000//main.html") # change main.html to your filename
while(1):
try:
browser.current_url # tries to see current url of browser, will throw exception if browser is closed
sleep(1) # save some resources
except:
break
print("Browser closed! Closing server...")
Popen.terminate(p) # close the http server
if __name__ == '__main__':
main()