Search code examples
javascriptmeta

Separate incoming content from a meta tag in Javascript


Okay I'm currently scraping a website by it's meta tag and getting a result back from it with this line of code:

 var affiliation = doc.getElementsByTagName('meta')[property='citation_author_institution'].content;    

Now I wanna try to separate the incoming content by using ; in some way so I can easily divide the content.

I tried something like this:

 if (affiliation)
                    {
                            for (i=0; i<affiliations.length; i++)
                            {
                                    affiliation.push(affiliations[i].textContent)
                            }

                            item.extra = affiliation.join("; ");
                    }

extra is the field I wanna put it in, and I created an array so I can store all incoming content. But when I try this in my program I get an error saying something like:

"Type errorr: affiliation.join is not at function"

What can I do instead?


Solution

  • I solved this by doing something like this instead:

    for (i=0; i<affiliations.length; i++) {
        if (affiliations[i].getAttribute("name") == "citation_author_institution") {
            affiliationArr.push(affiliations[i].content);
        }
    } 
    item.extra = affiliationArr.join("; ");