读取 javascript 变量的值 [英] Reading a javascript variable's value

查看:29
本文介绍了读取 javascript 变量的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


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


I want to read the value of a javascript variable using Xpath
the js text is as follows:

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

我只想要 item_phone 值
我试过:

I only want item_phone value
I tried :

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

它返回

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

我用 ',' 分割了它,但它返回相同的文本,我的问题是什么?

I split it by ',' but it return same text, what is my problem ?

推荐答案

您的代码

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

返回整个字符串.试试 xpath

returns the whole string. Try the xpath

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

这篇关于读取 javascript 变量的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆