Su Sheng no doubt 167 original articles, the public number set as a star, the first time to see the latest article.

I have previously written the following about backups:

Talk about backing up your twitter

Back up microblog with one click and export to generate PDF. Analyze microblog account data with Python

Talk about backup web pages and public articles

How to backup the public number articles and web pages that may be deleted

Want to see the public number article was deleted how to do?

Backup method number are written on it a single backup, if you want to backup some public number to all the posts that are a bit too much trouble, so today’s share is a key in Python backup a public issue of all articles, here on my own number public Su Sheng perplexity, for example, the principle is through the caught fetching WeChat client interface, Use Python to request wechat interface to obtain the link of the article of the official number and then download it.

Charles caught

A common type of grabber is Fiddler Charles. Charles is used here. Go to the official website firstwww.charlesproxy.com/downloadDownload the software, then open the wechat client to find the official account, enter the list of articles to see the sent articles.

Charles cannot obtain HTTPS interface data before the certificate is installed, and unknown is displayed.After installing the certificate, add the domain name and host in proxy-> SSL Proxying Settings.Crawl again can see the public number article interface data.

The interface address of the public account articleMp.weixin.qq.com/mp/profile_…The useful parameter __biz is the unique ID between the user and the public number, uin is the user ID, which is unchanged, key is the secret key of the request, which will be invalid after a period of time, offset is the offset, count is the number of requests.

As you can see, the returned data includes titile, digest, content_URL, source_URL, cover, and author. Just grab the useful data.

Python crawls public articles

After analyzing the interface parameters and the returned data, start using Python to request the wechat interface.

Here only crawl original articles, my public number has more than 160 original, generate HTML files in 2 minutes.Just open it up in Google Chrome.

The generated HTML files can also be converted to CHM format by installing Easy CHM, a powerful quick creation tool for CHM e-books or CHM help fileswww.etextwizard.com/cn/easychm…. The title is on the left and the content is on the right, which looks very convenient.Then compile it into a CHM file that you can double-click to open and browse.

There is also a Markdown file with the article title and link, which was covered in the previous article about MarkdownUse Markdown to write your resume and powerpoint.Excel file formats are also available.

Generating HTML, Markdown, and Excel are all faster because they’re all text, so let’s start exporting PDF.

Export PDF

Tools are educed PDF wkhtmltopdf, first to the website wkhtmltopdf.org/downloads.h… Download and install WkHTMLTopdf, set up the environment variables after installation, and then generate PDF directly from the command line.

Lambda wkhtmltopdf HTTP://www.baidu.com baidu.pdf
Loading pages (1/6)
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done
Copy the code

For example, generate a PDF of baidu’s home page.Python uses the pdfkit module to call wkhtmltopdf, firstpip install pdfkit -i http://pypi.douban.com/simple --trusted-host pypi.douban.com To install it.

Run the program again, and the PDF file is generated.PDF can also be opened in Chrome, like this oneOne click to unlock netease Cloud Music gray songs.

However, due to the slow generation of PDF, if there are many articles, the key parameter will be invalid, so you need to obtain it again, and then modify next_offset to continue fetching.{'base_resp': {'ret': -3, 'errmsg': 'no session', 'cookie_count': 0, 'csp_nonce': 406210942}, 'ret': -3, 'errmsg': 'no session', 'cookie_count': 0}

This is perfect to download all my articles to the local public account, HTML, PDF, Excel, Markdown, CHM format (in the public account background replyThe public,Get all my original articles, if you want to download the public number can add my wechat free help download).

One problem is that if the official account has paid articles, only part of the content can be downloaded.

There are also comments on the article interface access, free to study again.

Public account Su Sheng no doubt