-
Notifications
You must be signed in to change notification settings - Fork 0
/
selenium_webdriver.py
56 lines (43 loc) · 1.63 KB
/
selenium_webdriver.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
46
47
48
49
50
51
52
53
54
55
56
#/bin/python
# Program for messing with web driver
from selenium import webdriver
import logging
from optparse import OptionParser
from urlparse import urlparse
def screen_cap(site, output):
driver = webdriver.Firefox()
driver.set_window_size(1024,480)
driver.get(site)
driver.save_screenshot(output)
driver.quit()
def main():
# Setup the command line arguments.
optp = OptionParser()
# Output verbosity options
optp.add_option('-q', '--quiet', help='set logging to ERROR',
action='store_const', dest='loglevel',
const=logging.ERROR, default=logging.INFO)
optp.add_option('-d', '--debug', help='set logging to DEBUG',
action='store_const', dest='loglevel',
const=logging.DEBUG, default=logging.INFO)
optp.add_option('-v', '--verbose', help='set logging to COMM',
action='store_const', dest='loglevel',
const=5, default=logging.INFO)
# Option for site to browse to
optp.add_option("-s", "--site", dest="site",
help="The site to browse to")
# Option for name of the screenshot
optp.add_option("-o", "--out", dest="output",
help="The name the screenshot saves to")
opts, args = optp.parse_args()
if opts.site is None:
opts.site = raw_input("which site do you want to browse to: ")
if opts.output is None:
parsed = urlparse(opts.site)
domain = parsed.netloc
opts.output = str(domain)+".png"
print "Output file not specified, saving as: "+opts.output
# run main functions
screen_cap(opts.site, opts.output)
if __name__ == '__main__':
main()