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 966875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:13:44+00:00 2026-05-16T02:13:44+00:00

My html looks like: <td> <table ..> <tr> <th ..>price</th> <th>$99.99</th> </tr> </table> </td>

  • 0

My html looks like:

<td>
   <table ..>
      <tr>
         <th ..>price</th>
         <th>$99.99</th>
      </tr>
   </table>
</td>

So I am in the current table cell, how would I get the 99.99 value?

I have so far:

td[3].findChild('th')

But I need to do:

Find th with text ‘price’, then get next th tag’s string value.

  • 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-05-16T02:13:45+00:00Added an answer on May 16, 2026 at 2:13 am

    Think about it in “steps”… given that some x is the root of the subtree you’re considering,

    x.findAll(text='price')
    

    is the list of all items in that subtree containing text 'price'. The parents of those items then of course will be:

    [t.parent for t in x.findAll(text='price')]
    

    and if you only want to keep those whose “name” (tag) is 'th', then of course

    [t.parent for t in x.findAll(text='price') if t.parent.name=='th']
    

    and you want the “next siblings” of those (but only if they’re also 'th's), so

    [t.parent.nextSibling for t in x.findAll(text='price')
     if t.parent.name=='th' and t.parent.nextSibling and t.parent.nextSibling.name=='th']
    

    Here you see the problem with using a list comprehension: too much repetition, since we can’t assign intermediate results to simple names. Let’s therefore switch to a good old loop…:

    Edit: added tolerance for a string of text between the parent th and the “next sibling” as well as tolerance for the latter being a td instead, per OP’s comment.

    for t in x.findAll(text='price'):
      p = t.parent
      if p.name != 'th': continue
      ns = p.nextSibling
      if ns and not ns.name: ns = ns.nextSibling
      if not ns or ns.name not in ('td', 'th'): continue
      print ns.string
    

    I’ve added ns.string, that will give the next sibling’s contents if and only if they’re just text (no further nested tags) — of course you can instead analize further at this point, depends on your application’s needs!-). Similarly, I imagine you won’t be doing just print but something smarter, but I’m giving you the structure.

    Talking about the structure, notice that twice I use if...: continue: this reduces nesting compared to the alternative of inverting the if‘s condition and indenting all the following statements in the loop — and “flat is better than nested” is one of the koans in the Zen of Python (import this at an interactive prompt to see them all and meditate;-).

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

Sidebar

Related Questions

No related questions found

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.