from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
import time
import os
# chrome-driver 安装路径
DRIVER_PATH = '/usr/bin/chromedriver'
# 若是windows环境下
# DRIVER_PATH = 'C:\Program Files (x86)\Google\Chrome\Application\chromedriver'
img_path = '/data/script/py/img' # 存放截图的位置
if __name__ == "__main__":
# 浏览器基础配置
options = Options()
options.add_argument('--no-sandbox')
options.add_argument('--headless') # 无头参数
options.add_argument('--disable-gpu') # 禁用gpu 防止占用资源出现bug
options.add_argument('window-size=1920x1680') # 设置分窗口辨率
options.add_argument('--start-maximized') # 最大化运行(全屏窗口),不设置,取元素可能会报错
options.add_argument('--hide-scrollbars')
# 启动浏览器
driver = Chrome(executable_path=DRIVER_PATH, options=options)
try:
driver.get('http://106.14.147.238:3000/login')
time.sleep(2)
driver.find_element(By.NAME, 'user').send_keys('admin')
driver.find_element(By.NAME, 'password').send_keys('test_123')
driver.find_element(By.CLASS_NAME,'css-1daj7gy-button').click()
time.sleep(10)
driver.get('http://106.14.147.238:3000/d/d2s-16x/shi-li-xing-neng-ce-shi-d2s-16x?orgId=1&from=1644508800000&to=1644595199000&var-instance=g8y-8x003&var-netcard=eth0')
time.sleep(10)
# 访问页面
# 截屏
img_name = time.strftime(
'%Y-%m-%d', time.localtime(time.time())) # 截屏名称 时间表示
img = "%s.png" % os.path.join(img_path, img_name) # 图片
driver.get_screenshot_as_file(img) # 保存截图
except Exception as e:
print(e)
driver.close() # 关闭浏览器
driver.quit()