2015-04-24 98 views
0

我使用Jsoup解析以下webpage中的html。如何從變量price_ourBase獲得的價值:Jsoup - 提取變量值

<script type="text/javascript"> 
    var price_ourBase = 279; 
    . 
    . 
    . 
</script> 

JS:

Element upperContainer_inner = document.select("div.upperContainer_inner").first(); 
Element table = upperContainer_inner.select("table.645.0.left.0.0").first(); 
Element script = table.select("script").first(); 
Element base_ourPrice = script.select("base_ourPrice").first(); 
price = (?, not sure what to put here or if there is more code needed).text(); 

回答

0

我不認爲jSoup可以解析JavaScript的那樣。但是,你可以用jSoup選擇腳本的內容,然後你可以做類似

String[] result = script.toString().split(" "); 
if(result[1].equals("price_ourBase")) 
     System.out.println("Our price is "+result[3].split(";")[0]);