硒屏幕截图中的 Firefox unicode 框而不是字符

Firefox unicode boxes in selenium screenshot instead of characters

我在 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

也重新启动了,但没有帮助。

Found something on Reddit 关于这个。发布者声称他们通过安装 Noto Fonts 解决了这个问题:

sudo apt-get update
sudo apt-get install fonts-noto