python使用谷歌浏览器打开网页截取全图
生活随笔
收集整理的這篇文章主要介紹了
python使用谷歌浏览器打开网页截取全图
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
from selenium import webdriver
import os
# chromedriver的路徑,設置chrome開啟的模式,headless就是無界面模式
#一定要使用這個模式,不然截不了全頁面,只能截到當前頁面
chromedriver = r"C:\Google\Chrome\Application\chromedriver.exe"
os.environ["webdriver.chrome.driver"] = chromedriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
# 啟動瀏覽器
driver = webdriver.Chrome(options=chrome_options)
# 控制瀏覽器寫入并轉到鏈接
driver.get("url地址")
#driver.maximize_window()只能截取到當前頁面
# 接下來是全屏的關鍵,用js獲取頁面的寬高
width=driver.execute_script("return document.documentElement.scrollWidth")
height=driver.execute_script("return document.documentElement.scrollHeight")
print(width,height)
# 獲取瀏覽器的寬高
driver.set_window_size(width,height)
# 截圖并保存
driver.get_screenshot_as_file(r'D:\tupian.png')
#關閉瀏覽器
driver.quit()
總結
以上是生活随笔為你收集整理的python使用谷歌浏览器打开网页截取全图的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 1550A. Find The Arra
- 下一篇: cisco dhcp服务器 修改,思科D