Reputation: 298
Like the title says, I have a meta-tag that I need to scrape of some information. Link It's from this site I'm trying to extract the author affiliation from. And that information can I find in the using google development tools with this line of code:
document.getElementsByName('citation_author_institution')
Then I get back what I believe is a array of elements or nodes that looks like this:
[<meta name="citation_author_institution" content="Columbia University, New York">, <meta name="citation_author_institution" content="Columbia University, New York">, <meta name="citation_author_institution" content="Columbia University, New York">]
Now I need to just access the content and saving it an array so I can put it in my database. I have tried with stuff like
document.getElementsByName('citation_author_institution').textContent
document.getElementsByName('citation_author_institution').getAttribute('content')
But that doesnt work. Anyone have any idea or tip for me how to do this?
Upvotes: 0
Views: 106
Reputation: 488
You are very close. What you need to do is to iterate through the list of nodes:
var elements = document.getElementsByName('citation_author_institution')
var contents = []
for (var i = 0; i < elements.length; i++) {
contents.push(elements[i].content);
}
console.log(contents)
So, contents
will be your list of contents. Example here
https://jsfiddle.net/o3Lzm4ca/
Upvotes: 2
Reputation: 65
var authors = [];
var elements = document.getElementsByName('citation_author_institution');
for (var i=0; i<elements.length; i++){
authors.push(elements[i].content);
}
console.log(authors)
Upvotes: 1