This repository was archived by the owner on Apr 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathmain.py
More file actions
42 lines (36 loc) · 1.26 KB
/
main.py
File metadata and controls
42 lines (36 loc) · 1.26 KB
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
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
import sys
import os
def getUrls():
urlsStr = ""
# 从环境变量中获取
envUrlsStr = os.getenv('URLS')
urlsStr = envUrlsStr
# 从命令行参数中获取
if len(sys.argv) >= 2:
argUrlsStr = sys.argv[1]
if len(argUrlsStr) > 0:
urlsStr = argUrlsStr
urls = urlsStr.splitlines()
return urls
def save_screenshot(url):
driver.get(url)
width = driver.execute_script("return document.documentElement.scrollWidth")
height = driver.execute_script("return document.documentElement.scrollHeight")
driver.set_window_size(width, height)
driver.save_screenshot('./screenshots/' + time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())) +'.png')
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--headless')
driver = webdriver.Chrome('./chromedriver', options=chrome_options)
urls = getUrls()
urlsLen = len(urls)
print('一共有: ' + str(urlsLen) + ' 条URL')
for i in range(0, urlsLen):
time.sleep(5)
save_screenshot(urls[i])
print('截图成功: ' + urls[i])
print('运行完成')