微信公众号文章提取并保存为PDF

有时会看到非常好的公众号文章想保存下来供以后参阅,避免文章被删的情况,笔者介绍几种方法以供参考。

手动保存

找到公众号链接,如下篇:https://mp.weixin.qq.com/s/8fhYaOnAwqCOZwip__3zcg

 

 

在浏览器打开

 

 

 

然后 ctrl+p 

 

 

 

 点击保存即可。

 

存在问题,有的图片无法显示,可以在预览完成之后再保存。

 

利用python下载保存

 

首先,下载安装wkhtmltopdf,下载地址:https://wkhtmltopdf.org/downloads.html

 

 

 

记住安装的文件夹,添加环境变量。

 

 

 

打开cmd, 输入“ wkhtmltopdf ”,检查是否安装完成。

 

 

 

 

安装 pdfkit包,这个包是 wkhtmltopdf 实用程序,用于使用 Webkit 将 HTML 转换为 PDF

 

pip install pdfkit  (or pip3 for python3)

 

用法 

 

打开 IDLE

 

import pdfkit

pdfkit.from_url('http://360.com', 'out.pdf')
pdfkit.from_file('test.html', 'out.pdf')
pdfkit.from_string('Hello!', 'out.pdf')

  

输出即为PDF,完成显示True.

 

 

 

 

默认保存在python 的根目录下。

 

 

 

 

多个链接同时保存

 

pdfkit.from_url(['google.com', 'yandex.ru', 'engadget.com'], 'out.pdf')

  

 

用编辑器完成代码:

 

import pdfkit

url = 'https://mp.weixin.qq.com/s/8fhYaOnAwqCOZwip__3zcg'
pdfkit.from_url(url, 'out.pdf')

 

 

  

三行代码,即可下载。

 

 

import pdfkit

url = ['https://cn.bing.com','baidu.com']

pdfkit.from_url(url, 'out.pdf')

 

  

 

  

posted @ 2021-11-29 17:09  徐海建  阅读(2433)  评论(1编辑  收藏  举报