UnicodeEncodeError: 'ascii' codec can't encode character '\u2026' in position 45: ordinal not in range(128)が出たときに下のように書いたら治った。
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
技術系の備忘録.基本的に自分だけのためのものなので,詳しく書きません.検索でいらした方、すみません.
UnicodeEncodeError: 'ascii' codec can't encode character '\u2026' in position 45: ordinal not in range(128)が出たときに下のように書いたら治った。
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
> pdftocairo -svg file.pdf file.svgなぜcairoなのかよくわからない。。 ちなみに、ディレクトリにあるpdfを一括で変換するには
> foreach f in *.pdf ; do pdftocairo -svg $f $f:r.svg ; doneとすればいい。
version: '3'
services:
ubuntu:
build:
context: .
dockerfile: Dockerfile
container_name: ubuntu-test
stdin_open: true # docker run -i
tty: true # docker run -t
platform: linux/amd64
entrypoint: bin/bash
volumes:
- "/run/host-services/ssh-auth.sock:/tmp/ssh-agent.sock"
environment:
SSH_AUTH_SOCK: "/tmp/ssh-agent.sock"
最後のvolumeとenvironment がポイント。これはmacでのやり方なので、
linuxだとまた違うようだ。
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options=Options()
options.add_extension(pathToExtension)
driver = webdriver.Chrome("./chromedriver", options=options)
注意点としては、savefile.default_directory の指定はどうも絶対パスでないといけないようなので、 Pathを使って作ってやる必要がある。
pathToExtension="2.7.0_0.crx"
def optionsSetUp():
#印刷としてPDF保存する設定
options=Options()
appState = {
"recentDestinations": [
{
"id": "Save as PDF",
"origin": "local",
"account":""
}
],
"selectedDestinationId": "Save as PDF",
"version": 2,
"isLandscapeEnabled": False, #印刷の向きを指定 tureで横向き、falseで縦向き。
"pageSize": 'A4', #用紙タイプ(A3、A4、A5、Legal、 Letter、Tabloidなど)
"isHeaderFooterEnabled": False, #ヘッダーとフッター
"isCssBackgroundEnabled": True, #背景のグラフィック
"isCollateEnabled": True #部単位で印刷
}
prefs = {'printing.print_preview_sticky_settings.appState':
json.dumps(appState),
"savefile.default_directory": str(Path('../rendered').resolve())
} #appState --> pref
options.add_experimental_option('prefs', prefs)
options.add_argument('--kiosk-printing')
options.add_extension(pathToExtension)
return options
driver = webdriver.Chrome("./chromedriver", options=options)
driver.get(URL)
time.sleep(2) # ページが確実にレンダリングされるのを待つ
driver.execute_script('window.print();')
? show the help dialog for a list of all available keys
h scroll left
j scroll down
k scroll up
l scroll right
gg scroll to top of the page
G scroll to bottom of the page
d scroll down half a page
u scroll up half a page
f open a link in the current tab
F open a link in a new tab
r reload
gs view source
i enter insert mode -- all commands will be ignored until you hit Esc to exit
yy copy the current url to the clipboard
yf copy a link url to the clipboard
gf cycle forward to the next frame
gF focus the main/top frame
newpage
o Open URL, bookmark, or history entry
O Open URL, bookmark, history entry in a new tab
b Open bookmark
B Open bookmark in a new tab
find系
/ enter find mode
-- type your search query and hit enter to search, or Esc to cancel
n cycle forward to the next find match
N cycle backward to the previous find match
history
H go back in history
L go forward in history
tab
J, gT go one tab left
K, gt go one tab right
g0 go to the first tab. Use ng0 to go to n-th tab
g$ go to the last tab
^ visit the previously-visited tab
t create tab
yt duplicate current tab
x close current tab
X restore closed tab (i.e. unwind the 'x' command)
T search through your open tabs
W move current tab to new window
pin/unpin current tab