How do i get text node with XPATH contains?
Question:
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 & 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.
Answers:
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")]
.
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 & 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.
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")]
.