Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7880409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:08:20+00:00 2026-06-03T04:08:20+00:00

The xpath for text I wish to extract is reliably located deep in the

  • 0

The xpath for text I wish to extract is reliably located deep in the tree at

...table/tbody/tr[4]/td[2]

Specifically, td[2] is structured like so

<td class="val">xyz</td>

I am trying to extract the text “xyz”, but a broad search returns multiple results. For example the following path returns 10 elements.

xpath('//td[@class="val"]')

… while a specific search doesn’t return any elements. I am unsure why the following returns nothing.

xpath('//tbody/tr/td[@class="val"]')

One solution involves..

table = root.xpath('//table[@class="123"]')

#going down the tree
xyz = table[0][3][1]
print vol.text

However, I am pretty sure this extremely brittle. I would appreciate it if someone could tell me how to construct an xpath search that would be both un-brittle and relatively cheap on resources

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T04:08:21+00:00Added an answer on June 3, 2026 at 4:08 am

    You haven’t mentioned it explicitly, but if your target table and td tag classes are reliable then you could do something like:

    //table[@class="123"]/descendant::td[@class="val"]
    

    And you half dodge the issue of tbody being there or not.

    However, there’s no substitute for actually seeing the material you are trying to parse for recommending XPATH queries…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get the plain text from a word document. Specifically, the xpath
How to extract the text of such an element via XPath: <document> some text
doc.xpath(//div[@id='Ci_']).each_with_index do |div,i| parse_file.puts #{div.at_xpath(./*[@class='class1']).text} parse_file.puts #{div.at_xpath(./*[@class='class2']).text} There are two links in class2 and
I'm trying to write Selenium tests for HTML that's structured like this: <table> <tr
In Microsoft SQL Server 2008, when executing .query('{xpath}/text()') on an XML stream column value,
How do I select the globally-last text node using xpath? I tried this, but
how can i convert xpath like /html/body/div[3]/ul/li[1]/a[5] html > body > div[3] > ul
I have written a small function, which uses ElementTree and xpath to extract the
I have the following XPath to match authors name in an Amazon page: //div[@class='pTitle']/span[@class='small
I am using xpath to retrieve the text value of some links (a) in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.