Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env python
import sys
import time
from getopt import getopt
from PIL import Image
from selenium import webdriver
def capture(conf):
profile = webdriver.FirefoxProfile()
profile.set_preference("network.http.phishy-userpass-length", 255)
driver = webdriver.Firefox(firefox_profile=profile)
driver.get(conf["url"])
webdriver.ActionChains(driver).move_by_offset(0, 0).perform()
time.sleep(int(conf["sleep"]))
driver.save_screenshot(conf["out"])
driver.quit()
img = Image.open(conf["out"])
(w, h) = img.size
area = img.crop((0, 0, w-10, h))
area.save(conf["out"], conf["fmt"])
def main():
conf = {
"url": "https://freegeoip.net",
"sleep": "2",
"out": "out.png",
"fmt": "png",
}
args = "url= sleep= out= fmt=".split()
optlist, args = getopt(sys.argv[1:], "", args)
for k, v in optlist:
conf[k.lstrip("--")] = v
capture(conf)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment