Skip to content

Commit c825dba

Browse files
committed
Create selenium_webdriver.py
1 parent 16d33a7 commit c825dba

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

selenium_webdriver.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#/bin/python
2+
# Program for messing with web driver
3+
from selenium import webdriver
4+
import logging
5+
from optparse import OptionParser
6+
from urlparse import urlparse
7+
8+
9+
def screen_cap(site, output):
10+
driver = webdriver.Firefox()
11+
driver.set_window_size(1024,480)
12+
driver.get(site)
13+
driver.save_screenshot(output)
14+
driver.quit()
15+
16+
17+
def main():
18+
19+
# Setup the command line arguments.
20+
optp = OptionParser()
21+
22+
# Output verbosity options
23+
optp.add_option('-q', '--quiet', help='set logging to ERROR',
24+
action='store_const', dest='loglevel',
25+
const=logging.ERROR, default=logging.INFO)
26+
optp.add_option('-d', '--debug', help='set logging to DEBUG',
27+
action='store_const', dest='loglevel',
28+
const=logging.DEBUG, default=logging.INFO)
29+
optp.add_option('-v', '--verbose', help='set logging to COMM',
30+
action='store_const', dest='loglevel',
31+
const=5, default=logging.INFO)
32+
33+
# Option for site to browse to
34+
optp.add_option("-s", "--site", dest="site",
35+
help="The site to browse to")
36+
37+
# Option for name of the screenshot
38+
optp.add_option("-o", "--out", dest="output",
39+
help="The name the screenshot saves to")
40+
41+
opts, args = optp.parse_args()
42+
43+
if opts.site is None:
44+
opts.site = raw_input("which site do you want to browse to: ")
45+
46+
if opts.output is None:
47+
parsed = urlparse(opts.site)
48+
domain = parsed.netloc
49+
opts.output = str(domain)+".png"
50+
print "Output file not specified, saving as: "+opts.output
51+
52+
# run main functions
53+
screen_cap(opts.site, opts.output)
54+
55+
if __name__ == '__main__':
56+
main()

0 commit comments

Comments
 (0)