我必须从我的数据框中的 url 中提取一个特征 - 重定向的数量。有没有办法像在 python 中那样在 R 中找到数字:
r = requests.get(url)
i=0
for h in r.history:
i=i+1
print(i)
来自的返回值httr::GET
完全没有记录,但重定向的标头等似乎出现在$all_headers
对象中:
> url = "http://github.com"
> g = httr::GET(url)
> length(g$all_headers)
[1] 2
因为 http 重定向到 https。如果您直接转到 https,则不会看到重定向:
> url = "https://github.com"
> g = httr::GET(url)
> length(g$all_headers)
[1] 1
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句