Python Forum

Full Version: need help with xpath
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
<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()')
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'