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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:23:35+00:00 2026-06-05T15:23:35+00:00

I am using Python 2.7 lxml and I am having problems finding the table.

  • 0

I am using Python 2.7 lxml and I am having problems finding the table.

Finding it by id od class produces null result.

 a = [c.text for c in kontent.xpath('//table[@id="blk-ctnt-2308"[1]//tr/td[5]]

Any other suggestions?

Thank you

  • 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-05T15:23:36+00:00Added an answer on June 5, 2026 at 3:23 pm

    You are missing square brackets in the XPath expression, before the index [1]:

    a = [c.text for c in kontent.xpath('//table[@id="blk-ctnt-2308"][1]//tr/td[5]') ]
    

    Also, you may want to check if the first part of the expression works //table[@id="blk-ctnt-2308"][1] before you try out the full one.

    Finally, if the source table has an id attribute, the index [1] is redundant but should still work.

    Update

    I can’t use lxml on this machine, so I am using the ElementTree XML API in order to test the XPath, this code:

    import xml.etree.ElementTree
    
    html = '''<html>
    <head><title></title></head>
    <body>
    <table id="blk-ctnt-2308">
    <tr><td>1a</td><td>2a</td><td>3a</td><td>4a</td><td>5a</td><td>6a</td></tr>
    <tr><td>1b</td><td>2b</td><td>3b</td><td>4b</td><td>5b</td><td>6b</td></tr>
    <tr><td>1c</td><td>2c</td><td>3c</td><td>4c</td><td>5c</td><td>6c</td></tr>
    </table>
    <table id="blk-ctnt-2309">
    <tr><td>1a</td><td>2a</td><td>3a</td><td>4a</td><td>5a</td><td>6a</td></tr>
    <tr><td>1b</td><td>2b</td><td>3b</td><td>4b</td><td>5b</td><td>6b</td></tr>
    <tr><td>1c</td><td>2c</td><td>3c</td><td>4c</td><td>5c</td><td>6c</td></tr>
    </table>
    </body>
    </html>'''
    
    tree = xml.etree.ElementTree.fromstring(html)
    results = [ c.text
                for c in tree.findall('body/table[@id="blk-ctnt-2308"]//tr/td[5]') ]
    print results
    

    Produces this output:

    ['5a', '5b', '5c']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to parse an HTML table using lxml. While rows = outhtml.xpath('//tr/td/span[@class=boldred]/text()')
Using lxml in python I created this xpath syntax htmlPage.xpath(/html/body//a/text()) It gets me all
Question How do I remove class attributes from html using python and lxml? Example
Using Python I want to create a property in a class, but having the
I am trying to parse an XML file with python using lxml, but get
I am an XML beginner. I am using lxml python libs to process a
I am using lxml and python. I want to fetch the href for the
First, I installed lxml without using pip (Python 2.7.2 on Mac OS 10.6.8). Then,
I am using python lxml library to parse html pages: import lxml.html # this
I'm using python's lxml to validate xmls against a schema. I have a schema

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.