7

我正在尝试访问 Wikipedia 页面以获取页面列表,并收到以下错误:

library(RCurl)
u <- "http://en.wikipedia.org/w/index.php?title=Special%3APrefixIndex&prefix=tal&namespace=4"
getURL(u)
[1] "Scripts should use an informative User-Agent string with contact information, or they may be IP-blocked without notice.\n"

我希望通过 Wikipedia api 访问该页面,但我不确定它是否有效

问题是其他页面可以毫无问题地阅读,例如:

u <- "http://en.wikipedia.org/wiki/Wikipedia:Talk"
getURL(u)

有什么建议么?

旁注:一般来说,我宁愿不抓取 wiki 页面并通过 api,但我担心这个特定页面还不能通过 api 获得......

4

1 回答 1

13

根据的文档RCurlhttpheader,您可以通过添加参数来指定附加标头:

getURL(u, httpheader = c('User-Agent' = "Informative string with your contact info"))
于 2012-01-29T21:26:19.927 回答