Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6857023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:57:47+00:00 2026-05-27T01:57:47+00:00

I am using the below code to extract meta ‘generator’ tag content from a

  • 0

I am using the below code to extract meta ‘generator’ tag content from a web page using Jsoup:

Elements metalinks = doc.select("meta[name=generator]");
boolean metafound=false;

if(metalinks.isEmpty()==false)
{ 
    metatagcontent = metalinks.first().select("content").toString();
    metarequired=metatagcontent;
    metafound=true;
}
else 
{
    metarequired="NOT_FOUND";
    metafound=false;
}

The problem is that for a page that does contain the meta generator tag, no value is shown (when I output the value of variable ‘metarequired’. For a page that does not have meta generator tag, the value ‘NOT_FOUND’ is shown correctly. What am I doing wrong here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:57:47+00:00Added an answer on May 27, 2026 at 1:57 am

    From your code,

    metalinks.first().select("content").toString();
    

    This is not correct. This is merely selecting

    <meta ...>
        <content ... /> <!-- This one, which of course doesn't exist. -->
    </meta>
    

    while you actually want to get the attribute

    <meta ... content="..." />
    

    You need to use attr("content") instead of select("content").

    metatagcontent = metalinks.first().attr("content");
    

    See also:

    • Jsoup cookbook – Selector syntax
    • Jsoup Selector API documentation
    • W3 CSS3 selector specification

    Unrelated to the concrete problem, you don’t need to test against a boolean inside an if block. The isEmpty() already returns a boolean:

    if (!metalinks.isEmpty())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Beautiful Soup to extract 'content' from web pages. I know some
I am trying to retrieve a meta tag (Tag name=Generator) using Jsoup parser in
I'm using the code below to extract data from a gridview and populate it
I am using the HtmlAgilityPack to retrieve information from a web page and, at
With the code below I am trying to pull each url I extract using
I’m using Linq to extract values from some XML. Shown below is a simplified
i am using below code to change the the font type of text view.
Currently i'm using below code which works well. $(#topperAtBaseLevel:visible, #lowerAtBaseLevel:visible, #midAtBaseLevel).hide(); any optimised code?
I am using below code to create a reminder in Google calendar (using Google
In past, I am using Listview and using below code can show a particular

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.