0

我的 Html 文件如下所示:

<div class="mdt">
  Samsung Galaxy Y S5360
</div>
<div class="mdt">
  Samsung Champ Neo Duos C3262
</div>
<div class="mdt">
  Micromax Ninja A27
</div>
<div class="mdt">
  Karbonn S1 Titanium
</div>

<div class="priceDiv discTop">
  <span class="WebRupee WebRupeeMain">Rs.</span> 5,717
</div>
<div class="priceDiv discTop">
  <span class="WebRupee WebRupeeMain">Rs.</span> 3,004
</div>
<div class="priceDiv discTop">
  <span class="WebRupee WebRupeeMain">Rs.</span> 3,348
</div>
<div class="priceDiv discTop">
  <span class="WebRupee WebRupeeMain">Rs.</span> 9,306
</div>

我想显示输出是::

 Samsung Galaxy Y S5360    Rs. 5,717 

 Samsung Champ Neo Duos C3262   Rs. 3,004 

 Micromax Ninja A27    Rs. 3,348

为此,我正在使用 Jsoup Elements 类。我的实际代码是:

doc.select("body").select("table").select("div.mdt")

doc.select("body").select("table").select("div.priceDiv.discTop")

通过使用此代码,我可以单独显示。我使用了两个 for 循环来迭代这两个......

4

1 回答 1

0

I don'k know about Jsoup, but i can show how i can do it in java.

So you'll catch all the phones and prices and put it into a list.

List<WebElement> allPhones = driver.findElements(By.cssSelector("div.mdt"));
List<WebElement> allPrices = driver.findElements(By.cssSelector("div.priceDiv.discTop"));

since you have all that you can easily do that

for (int i = 0; i < allPhones.length; i++) {
  Systeme.out.println(allphones.get(i).getText() + " " + allPrices.get(i).getText());           
}
于 2013-04-17T09:59:29.360 回答