我正在使用Jsoup解析以下网页中的html。如何从变量中获取值price_ourBase:
<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();
我不认为jSoup可以像这样解析javascript。但是,你可以用jSoup选择脚本的内容,然后你可以做一些类似的事情
。String[] result = script.toString().split(" ");
if(result[1].equals("price_ourBase"))
System.out.println("Our price is "+result[3].split(";")[0]);