当我运行命令时
chromehtml2pdf --out=E:\Trial\test3.pdf https://www.wikiwand.com/en/Stochastic_process
在Windows命令提示符窗口中,它运行得很好,并在文件夹test3.pdf
中生成文件E:\Trial
,也可以通过以下方式输出:
Converting file: https://www.wikiwand.com/en/Stochastic_process
out = E:\Trial\test3.pdf
不幸的是,当我使用Python从Python调用此命令时>
import os cmd = "chromehtml2pdf --out=E:\Trial\test3.pdf https://www.wikiwand.com/en/Stochastic_process" os.system(cmd)
它不返回任何内容,即不生成PDF文件。
chromehtml2pdf
的完整文件名是:
C:\Users\Dung Le\AppData\Roaming\npm\chromehtml2pdf.cmd
我也尝试过:
import subprocess cmd = '"C:\Users\Dung Le\AppData\Roaming\npm\chromehtml2pdf.cmd" --out="E:\Trial\test1.pdf" http://www.randomservices.org/random/foundations/Measure.html' subprocess.run(cmd, shell = True)
但是它返回错误:
File "<ipython-input-21-4339c7e1a889>", line 2 cmd = '"C:\Users\Dung Le\AppData\Roaming\npm\chromehtml2pdf.cmd" --out="E:\Trial\test1.pdf" http://www.randomservices.org/random/foundations/Measure.html' SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 3-4: truncated \UXXXXXXXX escape.
我不知道怎么了:
cmd = '"C:\Users\Dung Le\AppData\Roaming\npm\chromehtml2pdf.cmd" --out="E:\Trial\test1.pdf" http://www.randomservices.org/random/foundations/Measure.html'
您能否详细说明这个问题以及如何解决?
当我在Windows命令提示符窗口中运行命令chromehtml2pdf --out = E:\ Trial \ test3.pdf https://www.wikiwand.com/en/Stochastic_process时,它运行得很好,并生成文件test3。 ...
@@ Mofu和@ HackingAddict1337的评论解决了我的问题。非常感谢!