-
Notifications
You must be signed in to change notification settings - Fork 1
/
screenshot.py
executable file
·48 lines (46 loc) · 1.73 KB
/
screenshot.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
#coding=utf-8
import time
import hashlib
import os
from datetime import date
from PIL import Image
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
if not os.path.exists('gov_images'):
os.makedirs('gov_images')
def screenshot(url):
options = webdriver.ChromeOptions()
options.headless = True
options.add_argument("--start-maximized")
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--disable-setuid-sandbox')
options.add_argument('--no-sandbox')
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument("--disable-blink-features=AutomationControlled")
driver = webdriver.Chrome(options=options)
try:
driver.get(url)
print("Screenshoting..." + url)
driver.get_screenshot_as_file("gov_images/web_screenshot.png")
#driver.find_element_by_tag_name('body').screenshot('gov_images/web_screenshot.png')
driver.quit()
except:
print(url + "was died")
pass
#resize gov_images
print("resizing...")
image = Image.open('gov_images/web_screenshot.png')
new_image = image.resize((250, 250))
name = hashlib.md5(url.encode())
new_image.save('gov_images/' + name.hexdigest() +'.png')
i=0
myfile = open("govt_urls_full.txt", "r")
while myfile:
url = myfile.readline()
i +=1
print(i)
screenshot(url)
if url == "":
break
myfile.close()