如何使用www.example.com功能从wordpress博客中获取所有帖子client.call?

kokeuurv  于 2023-01-04  发布在  WordPress
关注(0)|答案(2)|浏览(147)

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

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

但这是只返回最新的10个帖子,有没有办法得到所有的帖子?

cyvaqqii

cyvaqqii1#

我是这么做的:

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
qgzx9mmu

qgzx9mmu2#

根据文档,您可以传递一个参数,指示您想要检索多少帖子:
第一个月
或者,如果你想得到所有的帖子,看看这个:https://python-wordpress-xmlrpc.readthedocs.org/en/latest/examples/posts.html#result-paging

相关问题