1


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 Answer 1

4

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 = '"), "' ;")
Sign up to request clarification or add additional context in comments.

1 Comment

How should I use this on chrome console ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.