Rcurl:url.exists在url确实存在时返回false

Rcurl:url.exists在url确实存在时返回false,r,rcurl,httr,R,Rcurl,Httr,试图从特定网页下载信息,尽管它在任何浏览器中都可以正常打开,但RCurl表示它不存在: url.exists("http://www.transfermarkt.es/liga-mx-apertura/startseite/wettbewerb/MEXA") [1] FALSE 使用“.de”时的结果相同 当使用RCurl的其他函数时,它还返回一个错误 > htmlParse("http://www.transfermarkt.es/liga-mx-apertura/startseite

试图从特定网页下载信息,尽管它在任何浏览器中都可以正常打开,但RCurl表示它不存在:

url.exists("http://www.transfermarkt.es/liga-mx-apertura/startseite/wettbewerb/MEXA")
[1] FALSE
使用“.de”时的结果相同

当使用RCurl的其他函数时,它还返回一个错误

> htmlParse("http://www.transfermarkt.es/liga-mx-apertura/startseite/wettbewerb/MEXA")
Error: failed to load HTTP resource

> htmlTreeParse("http://www.transfermarkt.es/liga-mx-apertura/startseite/wettbewerb/MEXA")
Error: failed to load HTTP resource

> htmlParse(getURL("http://www.transfermarkt.es/liga-mx-apertura/startseite/wettbewerb/MEXA"))
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr>
<center>nginx</center>
</body>
</html>

当HTTP请求不包含用户代理字符串时,该Web服务器似乎返回403禁止的错误。默认情况下,RCurl不会传递用户代理。您可以使用
useragent=
参数设置一个

myurl<-"http://www.transfermarkt.es/liga-mx-apertura/startseite/wettbewerb/MEXA"
url.exists(myurl, useragent="curl/7.39.0 Rcurl/1.95.4.5")
# [1] TRUE
htmlTreeParse(getURL(myurl, useragent="curl/7.39.0 Rcurl/1.95.4.5"))
content(GET("http://www.transfermarkt.es/liga-mx-apertura/startseite/wettbewerb/MEXA"))
myurl<-"http://www.transfermarkt.es/liga-mx-apertura/startseite/wettbewerb/MEXA"
url.exists(myurl, useragent="curl/7.39.0 Rcurl/1.95.4.5")
# [1] TRUE
htmlTreeParse(getURL(myurl, useragent="curl/7.39.0 Rcurl/1.95.4.5"))
library(httr)
GET(myurl)