问题
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