如何从 R 访问维基百科? [英] How to access Wikipedia from R?

查看:36
本文介绍了如何从 R 访问维基百科?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何 R 包允许查询 Wikipedia(很可能使用 Mediawiki API)以获取与此类查询相关的可用文章列表,以及导入所选文章以进行文本挖掘?

Is there any package for R that allows querying Wikipedia (most probably using Mediawiki API) to get list of available articles relevant to such query, as well as import selected articles for text mining?

推荐答案

使用 RCurl 包获取信息,以及 XMLRJSONIO> 用于解析响应的包.

Use the RCurl package for retreiving info, and the XML or RJSONIO packages for parsing the response.

如果您使用代理,请设置您的选项.

If you are behind a proxy, set your options.

opts <- list(
  proxy = "136.233.91.120", 
  proxyusername = "mydomain\\myusername", 
  proxypassword = 'whatever', 
  proxyport = 8080
)

使用getForm 函数访问API.

search_example <- getForm(
  "http://en.wikipedia.org/w/api.php", 
  action  = "opensearch", 
  search  = "Te", 
  format  = "json",
  .opts   = opts
)

解析结果.

fromJSON(rawToChar(search_example))

这篇关于如何从 R 访问维基百科?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆