尝试通过以下方式更改用户代理时,我需要考虑什么特别的事情吗?httr::user_agent
in a httr::GET()
在 MS Windows 上调用?我在用着R-3.1.0
and httr 0.3
.
按照以下示例?user_agent
,我得到这些结果:
url_this <- "http://httpbin.org/user-agent"
标准用户代理:
GET(url_this)
Response [http://httpbin.org/user-agent]
Status: 200
Content-type: application/json
{
"user-agent": "curl/7.19.6 Rcurl/1.95.4.1 httr/0.3"
}
修改后的用户代理:
GET(url_this, user_agent("Mozilla/5.0"))
Response [http://httpbin.org/user-agent]
Status: 200
Content-type: application/json
{
"user-agent": "curl/7.19.6 Rcurl/1.95.4.1 httr/0.3"
}
我原以为第二次调用返回的结果更接近我访问时得到的结果url_this
在我的浏览器中:
{
"user-agent": "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0"
}
我在这里缺少什么?也跑了setInternet2(TRUE)
首先,但得到了相同的结果。
很好奇帮助页面?user_agent
建议它应该有效。您可以显式设置标头并且它确实有效
> GET("http://httpbin.org/user-agent", add_headers("user-agent" = "Mozilla/5.0"))
Response [http://httpbin.org/user-agent]
Status: 200
Content-type: application/json
{
"user-agent": "Mozilla/5.0"
}
但给出的例子?user_agent
看来不是。
> GET("http://httpbin.org/user-agent", user_agent("Mozilla/5.0") )
Response [http://httpbin.org/user-agent]
Status: 200
Content-type: application/json
{
"user-agent": "curl/7.19.6 Rcurl/1.95.4.1 httr/0.3"
}
>
它正在回归
> httr:::default_ua()
[1] "curl/7.19.7 Rcurl/1.95.4.1 httr/0.3"
我的 ISP 也在做一些有趣的事情,所以你可能需要:
GET("http://httpbin.org/user-agent", add_headers("user-agent" = "Mozilla/5.0", "Cache-Control" = "no-cache"))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)