Python Forum
need help with xpath - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: need help with xpath (/thread-23819.html)



need help with xpath - pythonprogrammer - Jan-18-2020

<p class='drug-subtitle'><b>Generic Name:</b> ziprasidone (zi PRAY si done)<br><b>Brand Names:</b> <i>Geodon</i></p>

i am trying to figure out what to enter for the xpath in the html code above to pull the word ziprasidone. I already figured out how to pull
Geodon by creating the variable as shown in the code below. If I change the /i/text() to /b/text() it prints {Generic Name:}{Brand Names:}. What would I need to change in the xpath shown below to pull the word ziprasidone?

brandname = tv.xpath('//p[@class="drug-subtitle"]/i/text()')



RE: need help with xpath - snippsat - Jan-18-2020

That would be the text under p tag,so should be like this.
tv.xpath("//p[@class='drug-subtitle']/text()")
That should give.
Output:
ziprasidone (zi PRAY si done)
So a quick clean up to get word.
>>> s = ' ziprasidone (zi PRAY si done)'
>>> s.strip().split(' (')[0]
'ziprasidone'