在浏览器中打开url http://quotes.money.163.com/f10/gszl_600024.html并等待5秒钟左右,url将重定向到http://quotes.money.163.com/stock中。在一些关于curl命令的教程中,L指令告诉cURL遵循重定向,s指令告诉cURL保持沉默,url_effective变量是我们想要的。
target="http://quotes.money.163.com/f10/gszl_600024.html"
curl -Ls -w %{url_effective} -o /dev/null $target为什么上面的命令无法获取最后一个重定向的url http://quotes.money.163.com/stock
发布于 2019-04-25 16:42:56
因为它是一个HTML meta tag redirect,而curl不支持自动跟随HTML meta标签重定向。要做到这一点,您需要一些能够理解HTML的东西,而curl则不需要。
quotes.money.163.com/f10/gszl_600024.html包含html标记<meta http-equiv="refresh" content="5; url=/">,它告诉浏览器after 5 seconds, redirect to the root of this domain哪个是quotes.money.163.com/,而quotes.money.163.com/反过来从http://img1.cache.netease.com/f2e/finance/backend_project/quotes_index_2014/app/dist/js/quotes_hub.916069.min.js加载javascript,它包含
! function(o) {
var l = location.href,
t = !!location.hash.split("#")[1] ? location.hash.split("#")[1] : "HS",
c = location.host,
n = location.protocol,
i = {
HS: "stock",
US: "usstock",
HK: "hkstock",
BOND: "bond",
FX: "old/#FX",
FN: "old/#FN",
FU: "old/#FU",
GB: "old/#GB",
DC: "old/#DC"
},
e = i[t],
a = n + "//" + c + "/stock";
function s() {
return l.indexOf("quotes.money.163.com/old/") > -1 ? 1 : 0
}
function r(o) {
return o.indexOf("query") > -1 ? 1 : 0
}
if (!s()) {
if (e) {
location.replace(n + "//" + c + "/" + e)
} else {
if (r(t)) {
location.replace(n + "//" + c + "/old/#" + t)
} else {
location.replace(a)
}
}
}
}(this);它通过修改window.location执行到http://quotes.money.163.com/stock的javascript重定向,更糟糕的是,curl既不理解javascript重定向,也不理解html重定向。如果你想要能同时理解这两种语言的东西,考虑使用无头浏览器。
https://stackoverflow.com/questions/55844427
复制相似问题