使用WP API获取帖子和图像

时间:2015-12-28 06:06:37

标签: python django wordpress

我正在使用Python(请求)和WP API将一些帖子从Wordpress博客传输到我的主门户网站。我的问题是我找不到从wordpress博客中检索“featured_image”的好方法。

我的python函数获取特定标记中所有帖子的列表:

def get_posts(self):

r = requests.get('http://papodebuteco.blog.br/wp-json/wp/v2/posts?tag=uberlandiahome?_embed',)
# we have the result on http://papodebuteco.blog.br/wp-json/wp/v2/posts?tag=uberlandiahome?_embed
if r.ok:
    data = json.loads(r.content.encode('UTF-8'))

    for post in data:
        image_id = post['featured_image'] #it gives me a 275 id to be used on the next line
        req = requests.get('http://papodebuteco.blog.br/wp-json/wp/v2/media/%d'% image_id)
        # eg. http://papodebuteco.blog.br/wp-json/wp/v2/media/275/
        content = json.loads(req.content.encode('UTF-8'))
        print content['guid']

else:pass

在最终结果中,我需要的一切将是从Wordpress博客检索帖子并将其保存(包括精选图片)在Django数据库上。有没有好办法呢?

0 个答案:

没有答案
相关问题