简体   繁体   English

元素未通过使用jsoup处理

[英]elements are not handling by using jsoup

my Html file is look like this: 我的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>

I want to display the out put is :: 我想显示输出为::

 Samsung Galaxy Y S5360    Rs. 5,717 

 Samsung Champ Neo Duos C3262   Rs. 3,004 

 Micromax Ninja A27    Rs. 3,348

for this i am using Jsoup Elements class. 为此,我正在使用Jsoup Elements类。 My actual code is : 我的实际代码是:

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

and

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

by using this code, i am able to display individually. 通过使用此代码,我可以单独显示。 i used two for loops to iterate both ... 我用了两个for循环来迭代两个...

I don'k know about Jsoup, but i can show how i can do it in java. 我不了解Jsoup,但我可以展示如何在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());           
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM