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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:39:48+00:00 2026-06-11T16:39:48+00:00

I scrape web pages with lxml in Python. Yet, to get the number of

  • 0

I scrape web pages with lxml in Python. Yet, to get the number of table rows I first get them all and then use len() function. I feel it’s wasteful, is there other way to get their number (dynamic one) for further scraping?

import lxml.html
doc = ''
try:
    doc = lxml.html.parse('url')
except SkipException: pass 

if doc: 
    buf = ''
    #get the total number of rows in table
    tr = doc.xpath("/html/body/div[1]/div[1]/table[1]/tbody/tr")
    table = []
    # iterate over the table rows limited to max number
    for i in range(3, len(tr)):
            # get the rows content                                              
            table += doc.xpath("body/div[1]/div[1]/table[1]/tbody/tr[%s]/td" % i)
  • 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-11T16:39:49+00:00Added an answer on June 11, 2026 at 4:39 pm

    You can use the tr elements you matched as the starting point, you can simply iterate over them like you would with a python list:

    tr = doc.xpath("/html/body/div[1]/div[1]/table[1]/tbody/tr")
    for row in tr[3:]:
        table += row.findall('td')
    

    The above uses .findall() to grab all contained td elements, but you could use further .xpath() calls if you need more control.

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

Sidebar

Related Questions

Hi I am trying to scrape other people web pages (for the forces of
I'm using cURL to scrape web pages but I can only seem to scrape
I am getting the following encoding error when trying to scrape web pages with
I am using scrapy to crawl all the web pages under a domain. I
I'm writing a web scraper in python, using httplib2 and lxml (yes - I
I want to scrape data from PHP web pages that are behind a login
I would like to web-scrape the html source code of java-script pages that I
I'm trying to scrape the data off a web page using the python Windmill
I would like to scrape web pages that load content dynamically with Javascript or
I have a function which uses Drakma to GET a web page: (defun scrape

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.