0

I am looking to scrape a page for any social media links. I wrote some code but I am getting an undefined message in the console. Can anyone help? Autistic and Dyslexic here.

var links = document.querySelectorAll('a');
for (var i = 0; i < links.length; i++) {
    if (links[i].href.indexOf('facebook.com') > -1 || links[i].href.indexOf('instagram.com') > -1 || links[i].href.indexOf('youtube.com') > -1 || links[i].href.indexOf('twitter.com') > -1) {
        console.log(links[i].href);
    }
}
Ryan Perez
  • 139
  • 7
  • 1
    Can you paste a screenshot of the `undefined` in the console? – Konrad Nov 23 '22 at 21:52
  • your code seems to be working fine: [StackBlitz link](https://stackblitz.com/edit/js-1qdat1?file=index.js) – damonholden Nov 23 '22 at 21:56
  • _"Autistic here."_ - this isn't all that helpful: that describes 2/3rds of the users of this website, myself included. – Dai Nov 23 '22 at 21:57
  • @Konrad https://prnt.sc/7_SqND-qj4Ni – Ryan Perez Nov 23 '22 at 22:05
  • @RyanPerez you are getting `undefined` here, because javascript in console works in REPL mode. for loop is treated as an expression which returns `undefined` – Konrad Nov 23 '22 at 22:12
  • I don't know why you don't get any urls in the console, because it works fine for me on that site – Konrad Nov 23 '22 at 22:17

0 Answers0