Reading a javascript variable's value

与世无争的帅哥 提交于 2020-02-02 14:34:26

问题



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' ;

I only want item_phone value
I tried :

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

it returns

 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 ?


回答1:


your code

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

returns the whole string. Try the xpath

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


来源:https://stackoverflow.com/questions/21778534/reading-a-javascript-variables-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!