40 lines
1.5 KiB
Python
Executable File
40 lines
1.5 KiB
Python
Executable File
from selenium import webdriver
|
|
from selenium.webdriver.chrome.options import Options
|
|
import time
|
|
|
|
def screenshot():
|
|
options = Options()
|
|
options.add_argument("--headless") # 無頭模式
|
|
options.add_argument("--no-sandbox") # 避免權限問題
|
|
options.add_argument("--disable-dev-shm-usage") # 避免資源不足
|
|
options.add_argument("--disable-gpu") # 某些系統需要這個
|
|
options.add_argument("--window-size=800x600") # 設定解析度
|
|
|
|
# 啟動瀏覽器
|
|
driver = webdriver.Chrome(options=options)
|
|
|
|
# 先訪問首頁,讓 Session 建立
|
|
driver.get("https://tccmoapply.dba.tcg.gov.tw/tccmoapply/")
|
|
print("Waiting for session to establish...")
|
|
time.sleep(2) # 等待 2 秒確保 session 建立
|
|
|
|
# 再跳轉到目標頁面
|
|
target_url = "https://tccmoapply.dba.tcg.gov.tw/tccmoapply/maliapp/asp/aspcons_f000.jsp?MODE=SAVE&KIND=01&YY=109&NO1=0267&NO2=00&CG=05"
|
|
driver.get(target_url)
|
|
print("Navigated to target page, waiting for it to load...")
|
|
time.sleep(2) # 等待 2 秒確保頁面載入完整
|
|
|
|
# 滾動到頁面底部
|
|
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
|
|
print("Scrolling to the bottom...")
|
|
time.sleep(3) # 等待 3 秒確保頁面完全載入
|
|
|
|
# 截取整個頁面
|
|
driver.save_screenshot("screenshot.png")
|
|
print("Screenshot saved as 'screenshot.png'")
|
|
|
|
# 關閉瀏覽器
|
|
driver.quit()
|
|
if __name__ == '__main__':
|
|
screenshot()
|