简单爬虫获取博客园里的网页并转化成pdf文件

import pdfkit
import requests
import os
url='https://www.cnblogs.com/yychuyu/p/13619923.html'
a=requests.get(url)
b=open(r'./良许Linux.html','w',encoding="utf-8")
b.write(a.text)
b.close()
# a=pdfkit.configuration(wkhtmltopdf="C:/Program Files/wkhtmltopdf/bin/wkhtmltopdf.exe")
try:
    if not os.path.exists('./良许Linux.pdf'):
         pdfkit.from_file('./良许Linux.html', './良许Linux.pdf')
    else:
        print("文件已存在!")
except:
    pass

在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/liaoqingjian/article/details/108429721
今日推荐