1

我正在使用 python wordpress_xmlrpc 库来提取 wordpress 博客数据。我想获取我的 wordpress 博客的所有帖子。这是我的代码

client = Client(url, 'user', 'passw')
all_posts = client.call(GetPosts())

但这仅返回最新的 10 个帖子。有什么办法可以获取所有帖子吗?

4

2 回答 2

1

我就是这样做的:

from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import GetPosts
from wordpress_xmlrpc import WordPressTerm
from wordpress_xmlrpc.methods import posts


client = Client('site/xmlrpc.php', 'user', 'pass')
data = []
offset = 0
increment = 20
while True:
        wp_posts = client.call(posts.GetPosts({'number': increment, 'offset': offset}))
        if len(wp_posts) == 0:
                break  # no more posts returned
        for post in wp_posts:
                print(post.title)
                data.append(post.title)
        offset = offset + increment
于 2018-09-28T12:41:21.193 回答
0

根据文档,您可以传递一个参数,指示您要检索多少个帖子:

client.call(GetPosts({'number': 100}))

或者,如果您想获取所有帖子,请查看:https ://python-wordpress-xmlrpc.readthedocs.org/en/latest/examples/posts.html#result-paging

于 2015-06-02T05:40:49.430 回答