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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:58:22+00:00 2026-05-25T13:58:22+00:00

I have a HTML page with about 50 tables on it. Each table has

  • 0

I have a HTML page with about 50 tables on it. Each table has the same layout, but with different values, eg:

<table align="right" class="customTableClass">
<tr align="center">
<td width="25" height="25" class="usernum">value1</td>
<td width="25" height="25" class="usernum">value2</td>
<td width="25" height="25" class="usernum">value3</td>
<td width="25" height="25" class="usernum">value4</td>
<td width="25" height="25" class="usernum">value5</td>
<td width="25" height="25" class="usernum">value6</td>
<td width="25" height="25" class="totalnum">otherVal</td>
</tr>
</table>

My REST server is running django/python so in my urls.py I am calling my def parse_url(): function which obviously I want to do all the work in. My problem is, I’m pretty much a newbie when it comes to python, so literally just don’t know where to put my code. I have gotten some code from the HTMLParser python docs, and changed it as follows:

import urllib, urllib2
from django.http import HttpResponse
from HTMLParser import HTMLParser

    class MyHTMLParser(HTMLParser):
        def handle_starttag(self, tag, attrs):
            print "Encountered the beginning of a %s tag" % tag

        def handle_endtag(self, tag):
            print "Encountered the end of a %s tag" % tag

        def handle_data(self, data):
            HttpResponse("Encountered data %s" % data)


    def parse_url(request):
        p = MyHTMLParser()
        url = 'http://www.mysite.com/lists.asp'
        content = urllib.urlopen(url).read()
        p.feed(content)
        return HttpResponse('DONE')

This code, at the moment, doesnt output anything useful. It just prints out DONE, which isnt very useful.

How do I use the class methods such as handle_starttag()? Shouldnt these be called automatically when I use p.feed(content)??

Basically, what I’m trying to accomplish in the end is, when I go to mysite.com/showlist, to be able to output a list saying:

value1
value2
value3
value4
value5
value6

othervalue

This needs to be done in a loop, because there is roughly 50 tables with different values in each table.

Thanks for helping a beginner!!

  • 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-25T13:58:22+00:00Added an answer on May 25, 2026 at 1:58 pm

    You are printing the beginning of the answer to stdout, not django. Here is how to get HTMLParser to do your bidding:

    import urllib, urllib2
    from django.http import HttpResponse
    from HTMLParser import HTMLParser
    
    class MyHTMLParser(HTMLParser):
        def __init__(self, *args, **kwargs):
            self.capture_data = False
            self.data_list = []
            HTMLParser.__init__(self, *args, **kwargs)
    
        def handle_starttag(self, tag, attrs):
            if tag == 'td':
                self.capture_data = True
    
        def handle_endtag(self, tag):
            if tag == 'td':
                self.capture_data = False
    
        def handle_data(self, data):
            if self.capture_data and data and not data.isspace():
                self.data_list.append(data)
    
    def parse_url(request):
        p = MyHTMLParser()
        url = 'http://www.mysite.com/lists.asp'
        content = urllib.urlopen(url).read()
        p.feed(content)
        return HttpResponse(str(p.data_list))
    

    I would recommend putting the class into a utils.py file and keeping in the same folder as your views.py. Then import it in. This will help keep your views.py manageable by only containing views.

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

Sidebar

Related Questions

I have an html form (each form has different page, according to date), with
I currently have about 4 different database tables which output to html tables. Each
So I have a html page that has a form, and a table inside
I have a HTML page that scrolls up and down (not a lot, but
I have a table that displays pictures in each td element. The page is
I have three different tables that have the exact same style rules applied to
Possible Duplicate: Why not use tables for layout in HTML? I have read a
I have a html table in my page that I populate with items from
I have HTML page where windows media player is embedded. It works very well
I have HTML page with some HTML element with ID=logo . I need to

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.