代码
需要先安装wkhtmltopdf,下载路径https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox-0.12.5-1.mxe-cross-win64.7z,需FQ
import sys reload(sys) sys.setdefaultencoding('utf8') import pdfkit path_wk = r'E:\wkhtmltox\bin\wkhtmltopdf.exe' #安装位置 config = pdfkit.configuration(wkhtmltopdf = path_wk) pdfkit.from_url('https://www.cnblogs.com/', 'out1.pdf', configuration=config) # pdfkit.from_string('Hello!', 'out3.pdf', configuration=config)
输入文件如下
https://files.cnblogs.com/files/lurenjia1994/out1.pdf