如何从HTML中检索Java中的元素元素

时间:2014-07-17 12:30:11

标签: java jquery html jsoup

如果我有这样的代码

Elements e = d.select("div[id=result_52]");
System.out.println("elemeeeeeee" + e);

e的输出如下

elemeeeeeee<imagebox id="result_52" class="rsltGrid prod celwidget" name="B00BF9MZ44"> 
<div class="linePlaceholder"></div>
    <div class="image imageContainer"> 
        <a href="http://www.abcdefg.com/VIZIO-E241i-A1-24-Inch-1080p-tilted/dp/B00BF9MZ44/ref=lp_6459736011_1_53/190-4904523-2326018?s=tv&amp;ie=UTF8&amp;qid=1405599829&amp;sr=1-53">
    <div class="imageBox"> 
    <img src="http://ecx.images-abcdefg.com/images/I/51PhLnnk7NL._AA160_.jpg" class="productImage cfMarker" alt="Product Details" /> 
</div>

我想要两个内部的URL

1 个答案:

答案 0 :(得分:4)

您可以使用#获取特定的id

Element e = d.select("div#result_52").get(0);
String firstURL = e.select("a").attr("href"); //select the `a` tag and the `href` attribute.
String secondURL = e.select("img").attr("src");