Jsoupを使用して読み取り、結果をExcelシートにエクスポートしたいHTMLファイルがあります。その過程で、HTMLファイルに存在するすべての画像のlinks(src)を抽出したいと思います。
これが私が同じことをするために使用したコードスニペットです:
File myhtml = new File("D:\\Projects\\Java\\report.html");
//get the string from the file myhtml
String str = getFileString(myhtml);
//getting the links to the images as in the html file
Document doc = Jsoup.parseBodyFragment(str);
Elements media = doc.select("[src]");
//System.out.println(media.size());
for(Element imageLink:media)
{
if(imageLink.tagName().equals("img"))
//storing the local link to image as global variable in imlink
P1.imlink = imageLink.attr("src").toString();
System.out.println(P1.imlink);
}
}
リンクが必要なHTMLファイルに2つの画像があります。しかし、私が書いたコードは、ファイルに存在する最初の画像へのリンクのみを示しています。私のコードのエラーを見つけるのを手伝ってください!