3

Why is this request being made to localhost:

 {
  errno: -4078,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 443,
  config: {
    url: 'https:\\stackoverflow.com/users/login?ssrc=head&returnurl=https%3a%2f%2fstackoverflow.com%2f',
    method: 'get',
    headers: {
      Accept: 'application/json, text/plain, */*',
      'User-Agent': 'axios/0.19.2'
    },

I'm not using a localhost in my code. But for some reason axios seems to be using a local host. The code below is what's causing me the current problem I have whenever I test the function:

function Scraper(url: string, login_page?: string){
  if (login_page) {
    var link: string = 'https:\\' + url + '/' + login_page;
  }
  else {
    var link: string = 'https:\\' + url;
  }
    axios.get(link)
    .then(responce => {
      const html = responce.data;
      const $ = cheerio.load(html);
      const website_usr_field: Cheerio = $('input[type=email]');
      //if ()
      /*
      TODO:
      1) Create if statement for assigning login type variable for values.
      */
      const website_pwd_field: Cheerio = $('input[type=password]');
      console.log(website_usr_field);
      console.log(website_pwd_field);
      return website_usr_field && website_pwd_field;
    }).catch(console.error);
}
Sergio Ley
  • 85
  • 1
  • 14

1 Answers1

4

could it be an incorrect url?

change:

https:\\

to:

https://
Muhammad Ahmod
  • 649
  • 4
  • 15