Search code examples
javajsoup

Get meta tag value with Jsoup


I need to get one value from all meta tags:

Elements elements= document.getElementsByTag("meta");

I will get these elements:

<meta name="twitter:image" content="https://lh3.googleusercontent.com/0daLqxVdiOGXvHI1R5aUFf_6znVlBHMturM9SXnpOQagADdYJDycyPzT-btcntR4jW4=w600-h300-pc0xffffff-pd">
<meta name="appstore:developer_url" content="http://www.verylittlenightmares.com">
<meta name="appstore:bundle_id" content="eu.bandainamcoent.verylittlenightmares">
<meta name="appstore:store_id" content="eu.bandainamcoent.verylittlenightmares">
<meta itemprop="price" content="200,00&nbsp;$">
<meta itemprop="url" content="https://play.google.com/store/apps/details?id=eu.bandainamcoent.verylittlenightmares&amp;rdid=eu.bandainamcoent.verylittlenightmares&amp;feature=md&amp;offerId">

How can i get value (200,00 $) from this attribute?

<meta itemprop="price" content="200,00&nbsp;$">

Solution

  • private String getPrice(Document document) {
    
        Elements elements= document.getElementsByTag("meta");
    
        for (Element metaTag : elements) {
            String content = metaTag.attr("content");
            String itemprop = metaTag.attr("itemprop");
    
            if ("price".equals(itemprop)) {
                return content;
            }
        }
        return null;
    }