嗨,我对 Java 比较陌生,但我希望编写一个类,该类将使用 JSOUP 在 HTML 文件中找到所有 ALT(图像)属性。如果图像上没有替代文本并且是否有提醒用户检查它,我希望打印一条错误消息。
import java.io.File;
import org.jsoup.Jsoup;
import org.jsoup.parser.Parser;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.TextNode;
import org.jsoup.select.Elements;
public class grabImages {
                File input = new File("...HTML");
                Document doc = Jsoup.parse(input, "UTF-8", "file:///C:...HTML");
                Elements img = doc.getElementsByTag("img"); 
                Elements alttext = doc.getElementsByAttribute("alt");
                 for (Element el : img){
                     if(el.attr("img").contains("alt")){
                         System.out.println("is the alt text relevant to the image? ");
                         }
                         else { System.out.println("no alt text found on image");
                         }
                    }
}