1. 程式人生 > 其它 >微信公眾號文章提取並儲存為PDF

微信公眾號文章提取並儲存為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')