在Python中使用pdfkit将多个html文件转换为pdf

2024-06-02 08:38:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用pdfkik将多个html文件转换为pdf。这是我的代码:

from bs4 import BeautifulSoup
from selenium import webdriver
import pdfkit

driver=webdriver.Chrome()
driver.get('https://www.linkedin.com/in/jaypratappandey/')
time.sleep(40)
soup= BeautifulSoup(driver.page_source, 'lxml')
data=[]
f=open('htmlfile.html', 'w')
top=open('tophtmlfile.html', 'w')

for name in soup.select('.pv-top-card-section__body'):
    top.write("%s" % name)

for item in soup.select('.pv-oc.ember-view'):
    f.write("%s" % item)


pdfkit.from_file(['tophtmlfile.html', 'htmlfile.html'], 'jayprofile.pdf')

driver.quit()

此代码给出以下错误:

^{pr2}$

Tags: 代码infromimportpdftophtmldriver
1条回答
网友
1楼 · 发布于 2024-06-02 08:38:22

我也犯了同样的错误。您可能得到的错误是由于qt安装的不一致和兼容qt版本不可用造成的。 试着跑步

wkhtmltopdf

在你的终端上,看看你是否能找到“减少的功能”。在

如果是,那么我的假设是正确的,那么你最保险的选择就是从源代码编译它。在

相关问题 更多 >