I am trying to retrieve a meta tag (Tag name=Generator) using Jsoup parser in java.
The code I have is given below:
Elements metalinks=doc.select("meta"); // meta
boolean metafound=false;
for (Element singlemeta : metalinks)
{
metatagname = singlemeta.attr("abs:name");
metatagcontent = singlemeta.attr("abs:content");
if((metatagname=="Generator")||(metatagname=="generator")||(metatagname=="GENERATOR")){
// this is the tag we want to get value of...
metarequired=metatagcontent;
metafound=true;
}
}
if(metafound==false)
metarequired="NOT_FOUND";
However I am unable to extract the meta GENERATOR
tag correctly.
One example of this tag is now given below:
<meta name="generator" content="Test page" />
For the very first line in code given above, I also tried the following code but that also does not work:
//Elements metalinks= doc.getElementsByTag("meta");
How do I extract the meta tag correctly?
It almost looks as if you're making it too complicated. What if you started out with something simple like this:
Elements metalinks = doc.select("meta[name=generator]");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With