【问题标题】:How can RWordPress retrieve blog post content?RWordPress 如何检索博客文章内容?
【发布时间】:2016-10-14 00:41:42
【问题描述】:

我想从我的 WordPress 博客中检索帖子的内容。使用包RWordPress 可以直接检索类别、标签和标题,但是帖子的内容呢?

# Download and load the package
if (!require('RWordPress')) {
    devtools::install_github(c("duncantl/XMLRPC", "duncantl/RWordPress"))
  }

library(RWordPress)

# list all the functions in the package
lsf.str("package:RWordPress")

例如,这里是获取类别的代码,括号中是我的详细信息:

Cat <- getCategoryList(login = c([my user name] = '[my password'),
        .server = 'http://[my blog on].wpengine.com/xmlrpc.php')

链接的 SO 问题不适用,因为它不使用 RWordPress [HTML and CSS and PHP coding]

这个网站是关于在 WordPress 上发布的,而不是从 WordPress [publishing, not gettting] 检索。另一个问题像 RWordPress 和 getPosts 调用一样使用 xmlrpc,但它不依赖于 R。

Posts <- getPosts(num = 100, blogid = 0L, login = c([my user name] = '[my password]'), .server = 'http://[my blog name].wpengine.com/xmlrpc.php')

以上代码返回日期、标题和状态,但不返回内容。

感谢您的指导。

************************第一次回答后编辑

要求RWordPressXMLRPC,然后为登录和.server 定义一个对象,这里是控制台消息:

> getPageList(blogid = 0L, login = WordpressLogin, .server = WordpressURL)
Error in xml.rpc(.server, op, as.integer(blogid), names(login), as.character(login),  : 
  Problems

我发现“问题”对我来说不是信息丰富的错误消息。

【问题讨论】:

  • 编辑:在这里重新发布评论,这样它会更接近你的编辑——通常它会返回一些错误代码。仅当服务器上的 url of xmlrpc.php file 错误时,我才会收到此特定的“问题”错误。建议您直接在浏览器中输入查看。顺便说一句,我后来运行代码从远程服务器获取帖子,它仍然工作正常。

标签: r xml wordpress


【解决方案1】:

如果我遗漏了什么,请告诉我,但对我来说,帖子的 description 标识符似乎传达了整个文本。

RWordpress 映射XML-RPC wp 中的所有函数

if (!require('RWordPress')) {
  devtools::install_github(c("duncantl/XMLRPC", "duncantl/RWordPress"))
}
library(RWordPress)
options(WordpressLogin = c(myusername = 'mypassword'),
        WordpressURL = 'http://localhost/myblog/wordpress/xmlrpc.php')
# library(knitr)

# can refer this page
# http://codex.wordpress.org/XML-RPC_wp

#Rwordpress has a one to one mapping 
getCategories()

#get a list of pages
getPageList()
# pick one id from above list 
id=27
getPage(pageid = id)
# description seems to have all the text of post, even though the 
# document is sparse
getPage(pageid = id)$description

#similarly for posts
getPost(postid = 6)$description

我当然使用的是本地安装的博客,但我认为这应该可以远程工作。

【讨论】:

  • 非常感谢,R.S.,但请参阅我对问题的修改。
  • 一般会返回一些故障码。仅当服务器上的 url of xmlrpc.php file 错误时,我才会收到此特定的“问题”错误。建议您直接在浏览器中输入查看。顺便说一句,我后来运行代码从远程服务器获取帖子,它仍然工作正常。
  • 我检查了 URL 代码并得到了这条消息:“XML-RPC 服务器只接受 POST 请求。”我使用 WPEngine.com 作为我的主机。也许它会阻止其他服务器允许的内容?
  • 这意味着 xmlrpc.php 就在那里并且正在工作。如果参数设置正确,可能还有其他一些服务器配置问题。我觉得你应该联系楼主看看XMLRPC引擎有没有限制。
  • 确实,我的主机阻止了它。我会接受你的回答,因为你花了很多时间来帮助我。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-24
相关资源
最近更新 更多