简体   繁体   中英

How Can I get current URL in axios?

I am crawling web with Node.js library axios.

Enter below emphasised URL, URL change https://steamcommunity.com/profiles/76561198141252368/games/?tab=all to https://steamcommunity.com/id/mungmung01/games/?tab=all .

https://steamcommunity.com/profiles/76561198141252368/games/?tab=all

I want to get current URL( https://steamcommunity.com/id/mungmung01/games/?tab=all ) in below source code. Which variable return current URL?

const axios = require("axios");

const getHtml = async () => {
    try {
      return await axios.get("https://steamcommunity.com/profiles/76561198141252368/games/?tab=all");
   } catch (error) {
      console.error(error);
   }
};

getHtml()
    .then(
        console.log(/* Answer variable */)
    )
getHtml()
    .then((response) => {
        console.log(response.request.res.responseUrl);
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM