1
votes

I am new to using **XPath** and this may be a basic question. Kindly bear with me and help me in resolving the issue.

Link is here...

I would like to target the text that comes after the "Contact:" text. The "Contact:" is wrapped in a <b> tag. I want to target the name-value after the <b> tag.

I tried this xPath experession name = response.xpath('//div[@style="line-height: 1.5;"]/b').get() but it only return the Contact: text. I am interested in the text after this "Contact: " text.

<div class="vcard">
<h2><a class="fn org" target="_blank" title="https://patientcaremedical.com" href="https://patientcaremedical.com" onclick="trackClick(32589, 0)">Patient Care Medical</a><sup>&nbsp;<font color="red" size="2"><b>New!</b></font></sup></h2>
<div style="line-height: 1.5;">
<a title="info [at] patientcaremedical [.] com" href="/Patient_Care_Medical/rfq/sid32589.htm"><b><font color="red">Click Here To EMAIL INQUIRY</font></b></a>
<br><b>Contact: </b>Michael Blanchette - Marketing Director
<br>

enter image description here

1
What is the issue, exactly? Have you tried anything, done any research?AMC
I tried this xPath experession name = response.xpath('//div[@style="line-height: 1.5;"]/b').get() but it only return the Contact: text. I am interested in the text after this "Contact: " text. @AMCAwais
Does this answer your question? XPath to select following-siblingAMC
possible solution: response.xpath('//div[@style="line-height: 1.5;"]')[0].text_content().split("Contact: ")[1].strip() . This text node is not related to any tag. You may also try response.xpath('//div[@style="line-height: 1.5;"]/text()') and then filter received list.Vova

1 Answers

1
votes

Try:

//div//div[@style="line-height: 1.5;"]/normalize-space(text()[3])

or possibly:

//div//div[@style="line-height: 1.5;"]//text()[preceding-sibling::br][1]