读取javascript变量的值

时间:2014-02-14 11:45:47

标签: javascript xpath


我想用Xpath读取javascript变量的值 js文本如下:

 var item_url = 'nahodka_sobaki_prodam_schenkov_labradora_278393584'
  , item_phone = '994h4ada5cc0f9605334b81edd8a4ad548189hbfea9627bf5beb5cb7c699efh1daha84bda6a8ddec8bd33706bf0bc5h849098' ;

我只想要item_phone值
我试过了:

$x('//script[contains(.,"item_phone")]/text()')[0]

它返回

 var item_url = 'nahodka_sobaki_prodam_schenkov_labradora_278393584'
  , item_phone = '994h4ada5cc0f9605334b81edd8a4ad548189hbfea9627bf5beb5cb7c699efh1daha84bda6a8ddec8bd33706bf0bc5h849098' ;

我将它拆分为','但它返回相同的文字,我的问题是什么?

1 个答案:

答案 0 :(得分:2)

你的代码

$x('//script[contains(.,"item_phone")]/text()')[0]

返回整个字符串。试试xpath

substring-before(substring-after(//script[contains(.,'item_phone')]/text(), "item_phone = '"), "' ;")