I'm making a web scrapper and I need to remove everything before and after nike.com in this url :
https://www.nike.com/fr/t/chaussure-air-max-90-surplus-pour-rpgT3V/DC9389-001
Expected result = nike.com
I need it to match the name of my shop in my database and I struggle a lot since I'm not good enough with regex, thank you if you take the time to help me !
CodePudding user response:
let url = 'https://www.nike.com/fr/t/chaussure-air-max-90-surplus-pour-rpgT3V/DC9389-001';
let newUrlArray = url.split('/');
let domain = newUrlArray[2].slice(4,newUrlArray[2].length);
console.log(domain);
CodePudding user response:
You could use the built in URL API. It won't work in IE, but nobody cares about that anymore!
const url = 'https://www.nike.com/fr/t/chaussure-air-max-90-surplus-pour-rpgT3V/DC9389-001';
const host = new URL(url).host;
console.log(host.replace('www.',''));