Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
need help with xpath
#1
<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()')
Reply
#2
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'
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020