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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:02:29+00:00 2026-05-31T21:02:29+00:00

Well, i have written a simple python program that parses HTML with HTMLParser. Here

  • 0

Well, i have written a simple python program that parses HTML with HTMLParser. Here is my code

import re
import os.path
import getopt
import getpass
import atom
import getopt
import sys
import string
import cookielib
import ClientCookie
import urllib
import urllib2
from HTMLParser import HTMLParser
from htmlentitydefs import name2codepoint

url = 'http://distribucija.altpro.hr/cjenik_include.php'
all_data = []

def ReParse(pin):
  global values
  values = {'kaj' : 'sifra',
            'rijec' : pin,
            'prikaz' : '20' }
  data = urllib.urlencode(values)
  req = urllib2.Request(url, data)
  response = urllib2.urlopen(req)
  global the_page 
  the_page = response.read()


class MyHTMLParser(HTMLParser):
  def handle_data(self, data):
    all_data.append(data)

parser = MyHTMLParser()

ReParse('3884429')

parser.feed(the_page)
print all_data[74]



ReParse('1241236')
parser.feed(the_page)
print all_data[74]

Now, the first parser.feed(…. works and all_data[74] is right, but second feed gives exactly the same thing that the first one does, but it shouldn’t. Can anyone help me ?

  • 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-31T21:02:30+00:00Added an answer on May 31, 2026 at 9:02 pm

    You’re re-assigning values each time. You want to move this:

    values = {'kaj' : 'sifra',
            'rijec' : '', #notice the change to a blank string.
            'prikaz' : '20' }
    

    To the outside of ReParse. And then, inside of that function, you will want to put this:

    global values
    values['rijec'] = pin
    

    You also seem to have missed all_data. It does not exist in the MyHTMLParser scope.

    class MyHTMLParser(HTMLParser):
        def handle_data(self, data):
            # global statement should be her.
            all_data.append(data)
    

    I do feel that it might be a good idea to warn you that “global scope” is often not your best option, but that is a separate matter.

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

Sidebar

Related Questions

I have written a simple program using parallel python, and all works well. However,
I have an application written in C# that invokes some C code as well.
I've written a simple application that works with database. My program have a table
I have written a simple program that pings three sites and then reacts to
I have written a few MSBuild custom tasks that work well and are use
I have this linq query that works well (although it may be written better,
I have written a simple server - client program with Swing interface using singleton
I have a Delphi application that I have written a fairly simple wrapper .exe
I have written a simple Magento plugin that simply lists all sub categories that
I have written an (obviously) excellent tool in python (under linux) that I would

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.