0
我只是盯着學習Jsoup和他們的網站上的食譜,但我只是有點卡住文本添加到我已解析的元素。在鏈接之前和之後添加文本jSoup
try{
Document doc = Jsoup.connect(url).get();
Element add = doc.prependText("a href") ;
Elements links = add.select("a[href]");
for (Element link : links) {
PrintStream sb = System.out.format("%n %s",link.attr("abs:href"));
System.out.print("<br>");
}
}
catch(Exception e){
System.out.print("error --> " + e);
}
實例運行與google.com我得到
http://www.google.ie/imghp?hl=en&tab=wi<br>
http://maps.google.ie/maps?hl=en&tab=wl<br>
https://play.google.com/?hl=en&tab=w8<br>
但我真的想
<a href> http://www.google.ie/imghp?hl=en&tab=wi<br></a>
<a href> http://maps.google.ie/maps?hl=en&tab=wl<br></a>
<a href> https://play.google.com/?hl=en&tab=w8<br></a>
有了這個代碼,我已經得到過的頁面的所有鏈接,但我想也得到和標籤,所以我可以讓他們創建我的網頁。我已經嘗試添加一個字符串並預先添加文本,但似乎無法正確顯示。
感謝
感謝,如果我用它打印的頁面圖像過於每一件事情,所以它只是使用更好的元素將它縮小到剛開的情況下,文本和href鏈接。 – JohnnyQ
好的,你能發佈你想要選擇鏈接的HTML部分嗎?也許有些東西可以用來找到適當的鏈接。 – ollo