Pergunta

I am using the following code to extract all alt tags from an html file:

Elements imgs =  doc.select("img");

                    for (Element alts : imgs) {

                        String altText = alts.attr("alt");


                        if(!(alts.attr("alt").equals(null)))
                            System.out.println("alt tags: " + alts.attr("alt"));
                        //getGui().setTextVers("\r\n"  + ">\r\n" + altText + "\r\n" );

                    }

I would like to ignore the alt tags which are blank and just print out the tags that contain text. I am using an if statement to test for empty alt tags but it still prints out all alt tags even though some contain text. Could someone help please?

Thanks

Foi útil?

Solução

Maybe change your if statement to be:

if ((altText != null) && !altText.isEmpty())
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top