我在 Ubuntu 20.04 上使用 Firefox 和 Geckodriver(都在 WSL2 和單獨的 VM 上,結果相似)
sudo apt install firefox -y
wget https://github.com/mozilla/geckodriver/releases/download/v0.30.0/geckodriver-v0.30.0-linux64.tar.gz
tar -xvzf geckodriver*
chmod x geckodriver
sudo mv geckodriver /usr/local/bin/
# am using pipenv as a virtual env which brings in selenium
pipenv run python dm.py
運行 Python 腳本來截取非 EN 字符集的螢屏截圖給了我帶有(unicode 地址?)的矩形
from selenium import webdriver
import time
options = webdriver.FirefoxOptions()
options.headless = True
driver = webdriver.Firefox(options=options)
driver.set_window_size(1400, 2000)
driver.get("http://www.chinatoday.com.cn/")
time.sleep(1)
# fonts showing up as boxes with numbers
driver.save_screenshot("screenshot.png")
另存為:

在常規 Firefox 上,它使用 Microsoft YaHei 字體。

我試過了
sudo apt install ttf-mscorefonts-installer -y
# update cache
sudo fc-cache -fv
也重新啟動了,這沒有幫助。
uj5u.com熱心網友回復:
在 Reddit 上找到了一些關于此的內容。海報聲稱他們通過安裝 Noto 字體解決了這個問題:
sudo apt-get update
sudo apt-get install fonts-noto
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/466292.html
