*** I took a screenshot of Megalodon with selenium and Chrome ***. *** It's a story *** ...
If you are local with the source code below I think you can take screenshots, *** You don't even need a virtual display ***. If you do it on the server, Japanese will be garbled with tofu type characters. I have to enter the Japanese font format. You need to be careful only there.
demo.py
# coding:utf-8
from time import sleep
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
import chromedriver_binary
from pyvirtualdisplay import Display
display = Display(visible=0, size=(1380,1124))
#Launch virtual display
display.start()
options = Options()
options.add_argument('--no-sandbox')
options.add_argument('--lang=ja-JP')
options.add_argument('--window-size=1280,1024')
#Launch Chrome
browser = webdriver.Chrome(options=options)
#Open the site you want to view
browser.get("https://megalodon.jp/")
#Take a screenshot of the site you viewed
browser.save_screenshot('screen.png')
sleep(2)
#Close browser
browser.close()
#Close virtual display
display.stop()
https://megalodon.jp/
Recommended Posts