As mentioned in the article [Python] Automatically post on WordPress through the "python-wordpress-xmlrpc" package, I want to download articles I have published on WordPress through Python for simple classification. Among them, what I found was the module named python-wordpress-xmlrpc
.
If you are interested in this package, welcome to their PyPI: https://pypi.org/project/python-wordpress-xmlrpc/
How to Download Articles
If you use this package in the first time, you can use the following command to install it:
pip3 install python-wordpress-xmlrpc
And confirm the sample code:
# -*- coding: utf-8 -*- import json from wordpress_xmlrpc import Client from wordpress_xmlrpc.methods import posts # Login with open('account.json', 'r', encoding='utf-8') as f: account = json.load(f) id = account['user'] password = account['password'] client = Client('http://clay-atlas.com/xmlrpc.php', id, password) data = [] offset = 0 increment = 10 index = 0 while True: wp_posts = client.call(posts.GetPosts({'number': increment, 'offset': offset})) if len(wp_posts) == 0: break for post in wp_posts: index += 1 print(index, post.title) data.append(post.title) offset = offset + increment
Output:
Yeah, I know that I have 246 articles right now! (Contains Drafts)
If you want to use the code, remember to change the URL, account number and password to your own. If you still want to download the content, just replace post.title
with post.content
.