通过url-python获取WordPress博客内容



我一直在尝试从我的WordPress博客中获取内容。我有每个帖子的URL,我尝试过Beautiful Soup。但它似乎需要很多regex,仍然没有给我所需要的(只有内容,没有其他(。

所以我现在使用wordpress_xmlrpc

from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import GetPosts, NewPost
from wordpress_xmlrpc.methods.users import GetUserInfo
from wordpress_xmlrpc import WordPressPost
client = Client("https://sitename/xmlrpc.php", 'username', 'password')
all_posts = client.call(GetPosts({'number':50', 'post_status':'publish'}, results_class=WordPressPost))
print all_posts

这给了我一份我发表的帖子的列表。如何获取内容而不仅仅是标题?(我确实有一个我的帖子的所有URL列表(

好吧,看起来这很容易。对于任何正在寻找此解决方案的人-首先收集帖子的ID,然后获取内容。

one_post=client.call(GetPost(all_posts[0].id))
print one_post.content

这是有效的,从文件中得到了它。

最新更新