python3 selenium squoosh(網頁版) 批量壓縮圖片


 

Squoosh 是谷歌推出的一款在線圖像壓縮工具,可幫助網站開發人員快速壓縮圖片,在保持圖片質量的同時,提升網站訪問速度。

Squoosh 使用起來也非常簡單,在瀏覽器中打開頁面后,可點擊選擇或直接往里面拖圖片,在左下方可選擇想要生成的圖片格式,右下方選擇圖片質量,再下載即可。

 


 

 

本次使用的代碼已經放到github上了(https://github.com/fusu192/Batch-image-compression

項目運行前,需先配置好selenium環境,以及python3環境

筆者環境為:mac,python3.6,selenium3.141.0

 

工作目錄結構,目標文件夾pic中有兩個相冊,每個相冊中有3張圖片,我們需要壓縮所有相冊里面的圖片

 

然后我們運行py文件,下面的是輸出日志

macname@MacdeMBP case % python3 compress_pic.py

本次任務共有2個.

開始處理------->1/2----------->test1

1/1/2-------------------->test1

還沒有出現結束標志---

Message: no such element: Unable to locate element: {"method":"xpath","selector":".//div[@class="hc73a"]/span/span"}

  (Session info: chrome=85.0.4183.121)

 

還沒有出現結束標志---

Message: no such element: Unable to locate element: {"method":"xpath","selector":".//div[@class="hc73a"]/span/span"}

  (Session info: chrome=85.0.4183.121)

 

13% smaller

轉換完成---

50

27.4

3

1.71

2/1/2-------------------->test1

72% smaller

轉換完成---

50

31.6

3

1.85

3/1/2-------------------->test1

67% smaller

轉換完成---

50

17.4

3

1.43

開始處理------->2/2----------->test2

1/2/2-------------------->test2

59% smaller

轉換完成---

50

20.2

3

1.47

2/2/2-------------------->test2

26% smaller

轉換完成---

50

30.9

3

1.86

3/2/2-------------------->test2

14% smaller

轉換完成---

50

27.2

3

1.94

macname@MacdeMBP case % 

 

壓縮過程視頻鏈接

https://github.com/fusu192/Batch-image-compression/blob/master/6cf91a644c2f0edc79d8d7cdcd3b4acc.gif

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM