0

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:

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.

1 Answer 1

4

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")].

Sign up to request clarification or add additional context in comments.

3 Comments

why should i use . instead of text() in contains part?
@BillyJhon . means "current node" and you've already selected the text nodes you want with "text()".
@BillyJhon, if you had e.g. text()[contains(text(), 'foo')] you would try to select a text node that has a text node child node containing the string foo. But a text node doesn't have any child nodes, it is a leaf node.

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.