forked from Gielpy/traffic-time-lapse-helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebHandler.py
45 lines (40 loc) · 1.45 KB
/
WebHandler.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import time
from promptDependency import promptDependency
try:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
except:
promptDependency('Selenium for Python',
'https://pypi.python.org/pypi/selenium')
promptDependency('PhantomJS',
'http://phantomjs.org/download.html')
exit()
class WebHandler:
browser = None
##############################################################################
# sets up Selenium
def __init__(self, visual=False):
# uses visible Firefox window, for debugging
if visual:
self.browser = webdriver.Firefox()
# normally, invisible PhantomJS
else:
try:
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = (
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/53 "
"(KHTML, like Gecko) Chrome/15.0.87"
)
self.browser = webdriver.PhantomJS('phantomjs', desired_capabilities=dcap)
except:
promptDependency('PhantomJS', 'http://phantomjs.org/download.html')
exit()
self.browser.set_window_size(1920,1080)
##############################################################################
# screenshots a site on an interval
def screenshot(self, site, filename):
self.browser.get(site)
time.sleep(3) # allow scripts and data to populate
self.browser.save_screenshot(filename)
print('saved screenshot.')
return True