2017-02-15 219 views
0

我想要得到的价格,这product的细节与此代码:跨度返回空空白

Document doc = Jsoup.connect(url).get(); 
Element productitem = doc.select("div.right-container._right-container").first(); 
Iterator<Element> price = productitem.select("div.price._product-price").iterator(); 
System.out.println(price.next().text()); 
that returns empty whitespace 

也这样:

Elements span = doc.select("span"); 
System.out.println(spanText); 
for (Element e:span) 
    System.out.println(e.text()); 

返回空,一切都只是价格。

即使只是这样的:

Element productitem = doc.select("div.right-container._right-container").first(); 
System.out.println(productitem); 

将返回整条生产线<span>69.90</span>&nbsp; 是存在的一个原因,这个跨度是浏览器而不是Jsoup可见?

+0

你可以分享html吗?我在url上找不到任何东西 – soorapadman

+0

这正是浏览器检查元素上的点,它存在于jsoup中不可见 –

+0

我在不同的国家它迫使选择国家并继续。 – soorapadman

回答

0

你如何检查HTML?由F12或通过查看源?因为当我去查看源代码,我可以看到有HTML中没有价格:

<div class="price _product-price" tabindex="0">&nbsp;</div> 

当我看着HTML通过F12:

enter image description here

当我看着HTML通过查看源代码:

enter image description here

因此,通过Jsoup返回的结果是正确的。

但是当我在这个文件中寻找价格(为我的国家是199.00),我可以找到行是这样的:

"isBuyable":true,"price":19900,"tags" 

也许你应该尝试找到价格这种方式。

+0

看看这个类价格_产品价格,你会发现它 –

+0

@KhalilM,有此类的一个条目,这一个我在答复中发布了这些信息。当您在F12之后查看元素中的源时,此类中存在价格范围。但是,当您点击页面上的右键并选择查看源代码时,您应该只看到上面发布的代码行。 – porgo

+0

我加了scrrenshots到我的答案。它看起来像Jsoup正在寻找代码在view-source中,你不应该建议一个F12的HTML。 – porgo