python - How to select two or more elements from the same node with Xpath? -


i select 2 elements same node. here code:

<div >   <span >first element select:</span>   <span ></span>   <strong >second element select</strong> </div> 

i have tried this:

$x('//div/span/text()') 

and array this:

["first element", " "] 

is there anyway get:

["first element", "second element"] 

and perhaps put python dictionary? , have:

dict = {'first element' : 'second element'} 

many helping

you can use following xpath :

//*[@id="details"]//div/*/text() 

or if want text nodes span , strong :

//*[@id="details"]//div/*[self::span|self::strong]/text() 

to skip empty text nodes, add predicate [normalize-space()] :

//*[@id="details"]//div/*/text()[normalize-space()] 

Comments

Popular posts from this blog

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -