【发布时间】:2021-08-09 22:42:25
【问题描述】:
我试图在从 Axios 重定向后获取网页的 URL,但 Axios 配置中似乎没有在重定向后给我预期的 URL。
我认为我传递了正确的搜索框参数,以获取我的输出 URL。但我无法确定,因为我看不到响应 URL。
我的目标——获取网址:https://www.redfin.com/GA/Lawrenceville/2105-Bentbrooke-Trl-30043/home/24906463
我的代码:
var querystring = require("querystring");
let axios = require("axios");
async function run() {
let rf = await axios.post(
"https://www.redfin.com",
querystring.stringify({
searchInputBox: "2105 bentbrooke trl",
}),
{
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
}
);
console.log(`RF URL: `, rf.config, rf.request.res.responseUrl);
}
run();
我目前的输出:
RF URL: {
url: 'https://www.redfin.com',
method: 'post',
data: 'searchInputBox=2105%20bentbrooke%20trl',
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'axios/0.21.1',
'Content-Length': 38
},
transformRequest: [ [Function: transformRequest] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 0,
adapter: [Function: httpAdapter],
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
validateStatus: [Function: validateStatus]
} https://www.redfin.com/
类似的问题,但这里没有一个对我有用的建议答案(我认为 Axios 可能已经更新,或者由于我使用的异步调用而存在一些差异):how to get the landing page URL after redirections using axios
【问题讨论】: