2017-02-15 221 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