0
我在使用jsoup獲取圖像的絕對URL時發生錯誤。JSOUP:獲取圖像的絕對URL時出錯
代碼:
package org.zzz.parser;
import java.io.File;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
public class DocumentParser {
/**
* Parsing html from file
*/
public static void main(String[] args) {
String url = "www.guiabh.com.br/evento/back-in-jack-seu-madruga.aspx";
File input = new File("/home/thalesfc/Code/recSystem/wgetao/" + url);
Document doc = null;
// parsing the document
try {
doc = Jsoup.parse(input, "ISO8859-1", url);
} catch (IOException e) {
System.err.println("$ Erro ao fazer o parsing do arquivo: " + input.getName());
e.printStackTrace();
}
//getting the image url
Element image = doc.getElementById("ctl00_ContentPlaceHolderConteudo_controleInternoAgito1_imageFotoCasa");
String imageUrl = image.attr("src");
String imageRealUrl = image.absUrl("src");
String imageRealUrl2 = image.attr("abs:src");
System.out.println("# image: " + imageUrl);
System.out.println("# real image: " + imageRealUrl);
System.out.println("# real image 2: " + imageRealUrl2);
}
}
輸出:
#圖像:../imgs_cadastradas/seu madruga.jpg
#實像:
#實像2:
理想的輸出是:http://www.guiabh.com.br/imgs_cadastradas/seu madruga.jpg
我做錯了什麼?