Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do i get text node with XPATH contains?

Im trying to get text node that contains some string, but it does not return anything.
Here is the page.

here is the html snippet:

<div id="FNA_envelop">✉ Corresponding authors: Wanli Liu, Department of Clinical Laboratory, Sun Yat-sen University Cancer Center, 651 Dongfeng Road East, Guangzhou 510060, Guangdong Province, China. Telephone/Fax: +86 20 8734 3438; E-mail: <a href="mailto:dev@null" data-email="nc.gro.ccusys@lwuil" class="oemail">nc.gro.ccusys@lwuil</a>; Min Deng, Affiliated Cancer Hospital &amp; Institute of Guangzhou Medical University, No.78, Hengzhigang Road, Guangzhou 510095, P. R. China. E-mail: <a href="mailto:dev@null" data-email="moc.361@590015nimgned" class="oemail">moc.361@590015nimgned</a>.</div>

My xpaths:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

response.xpath('//div[@id="FNA_envelop"]/*[contains(text(),"Deng")]')
[]
response.xpath('//div[@id="FNA_envelop"]/*[contains(.,"Deng")]')
[]

The idea is to get text node that contains name, then get following a tag and extract email(associated with name) from there.

>Solution :

Text nodes are selected with text(), thus, if you really want a text node (and not an element node containing the text) then I would expect you to use or suggest to use e.g. //div[@id="FNA_envelop"]/text()[contains(., "Deng")] or, if the text nodes are not (only) direct child nodes of the div but perhaps deeper inside other child or descendant elements, to use //div[@id="FNA_envelop"]//text()[contains(., "Deng")].

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading