473,734 Members | 2,511 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HTMLParser's start_tag method never called ?

Hi, python experts.

<console trace>
chaouche@CAY:~/TEST$ python nettoyageHTML.p y
chaouche@CAY:~/TEST$
</console trace>

This is the nettoyageHTML.p y python script

<code>
from HTMLParser import HTMLParser

class ParseurHTML(HTM LParser):
def __init__(self):
HTMLParser.__in it__(self)

def start_body(self ,attrs):
print "this is my body"

p = ParseurHTML()
p.feed(open("/home/chaouche/TEST/AJAX/testXMLRPC.html ","r").read ())
</code>

this is the testXMLRPC.html html file :

<html>
<head>
<script type="text/javascript" language="javas cript"
src="ClientXMLR PC.js">
</script>

<script type="text/javascript" language="javas cript" >

if (typeof netscape != 'undefined' && typeof netscape.securi ty !=
'undefined') {

netscape.securi ty.PrivilegeMan ager.enablePriv ilege('Universa lBrowserRea
d');
}

var chiffre = 0;
handler = function (self){
if (self.xmlhttp.r eadyState == 4) {
reponse = self.xmlhttp.re sponseText;
//dump(reponse); permet d'acceder au dom si ce qu'on a recu est une
forme de xml.
document.getEle mentById("txt") .innerHTML=repo nse;
}
}

function recupDonnees(){
chiffre+=1;
client = new ClientXMLRPC();
client.setUrl(" http://10.75.49.100:80 81/bonjour/sayHi?
chiffre="+chiff re);
client.executer ();
client.handlerE venement = handler;
}
recupDonnees();

</script>
</head>
<body>

<span id="txt">NON</span>
</body>
</html>
The script should output "this is my body", but nothing is printed.
Anyone ?

Y.Chaouche

Jan 29 '07 #1
3 1733
ychaouche wrote:
Hi, python experts.

<console trace>
chaouche@CAY:~/TEST$ python nettoyageHTML.p y
chaouche@CAY:~/TEST$
</console trace>

This is the nettoyageHTML.p y python script

<code>
from HTMLParser import HTMLParser

class ParseurHTML(HTM LParser):
def __init__(self):
HTMLParser.__in it__(self)

def start_body(self ,attrs):
print "this is my body"

p = ParseurHTML()
p.feed(open("/home/chaouche/TEST/AJAX/testXMLRPC.html ","r").read ())
</code>

this is the testXMLRPC.html html file :

<html>
<head>
<script type="text/javascript" language="javas cript"
src="ClientXMLR PC.js">
</script>

<script type="text/javascript" language="javas cript" >

if (typeof netscape != 'undefined' && typeof netscape.securi ty !=
'undefined') {

netscape.securi ty.PrivilegeMan ager.enablePriv ilege('Universa lBrowserRea
d');
}

var chiffre = 0;
handler = function (self){
if (self.xmlhttp.r eadyState == 4) {
reponse = self.xmlhttp.re sponseText;
//dump(reponse); permet d'acceder au dom si ce qu'on a recu est une
forme de xml.
document.getEle mentById("txt") .innerHTML=repo nse;
}
}

function recupDonnees(){
chiffre+=1;
client = new ClientXMLRPC();
client.setUrl(" http://10.75.49.100:80 81/bonjour/sayHi?
chiffre="+chiff re);
client.executer ();
client.handlerE venement = handler;
}
recupDonnees();

</script>
</head>
<body>

<span id="txt">NON</span>
</body>
</html>
The script should output "this is my body", but nothing is printed.
Anyone ?
You need a p.close() after the feed I guess.

Diez
Jan 29 '07 #2
On 29 jan, 16:45, "Diez B. Roggisch" <d...@nospam.we b.dewrote:
ychaouche wrote:
Hi, python experts.
<console trace>
chaouche@CAY:~/TEST$ python nettoyageHTML.p y
chaouche@CAY:~/TEST$
</console trace>
This is the nettoyageHTML.p y python script
<code>
fromHTMLParseri mportHTMLParser
class ParseurHTML(HTM LParser):
def __init__(self):
HTMLParser.__in it__(self)
def start_body(self ,attrs):
print "this is my body"
p = ParseurHTML()
p.feed(open("/home/chaouche/TEST/AJAX/testXMLRPC.html ","r").read ())
</code>
this is the testXMLRPC.html html file :
<html>
<head>
<script type="text/javascript" language="javas cript"
src="ClientXMLR PC.js">
</script>
<script type="text/javascript" language="javas cript" >
if (typeof netscape != 'undefined' && typeof netscape.securi ty !=
'undefined') {
netscape.securi ty.PrivilegeMan ager.enablePriv ilege('Universa lBrowserRea
d');
}
var chiffre = 0;
handler = function (self){
if (self.xmlhttp.r eadyState == 4) {
reponse = self.xmlhttp.re sponseText;
//dump(reponse); permet d'acceder au dom si ce qu'on a recu est une
forme de xml.
document.getEle mentById("txt") .innerHTML=repo nse;
}
}
function recupDonnees(){
chiffre+=1;
client = new ClientXMLRPC();
client.setUrl(" http://10.75.49.100:80 81/bonjour/sayHi?
chiffre="+chiff re);
client.executer ();
client.handlerE venement = handler;
}
recupDonnees();
</script>
</head>
<body>
<span id="txt">NON</span>
</body>
</html>
The script should output "this is my body", but nothing is printed.
Anyone ?

You need a p.close() after the feed I guess.

Diez
I tried p.close() and nothing happens.
Y.Chaouche

Feb 6 '07 #3
ychaouche wrote:
class ParseurHTML(HTM LParser):
def __init__(self):
HTMLParser.__in it__(self)

def start_body(self ,attrs):
print "this is my body"
def start_tag(self, name, attrs):
if name == 'body':
print "this is my body"
Feb 6 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2503
by: Adonis | last post by:
When parsing my html files, I use handle_pi to capture some embedded python code, but I have noticed that in the embedded python code if it contains html, HTMLParser will parse it as well, and thus causes an error when I exec the code, raises an EOL error. I have a work around for this as I use different set of characters rather that <tag> use something like (tag) then revert it back to <tag> via another function, I was wondering if there...
11
6065
by: Sean Cody | last post by:
I'm trying to take a webpage that has a nxn table of entries (bus times) and convert it to a 2D array (list of lists). Initially this was simple but I need to be able to access whole 'columns' of data so the 2D array cannot be sparse but in the HTML file I'm parsing there can be sparse entries which are repsented in the table as &nbsp entities. The sparse output breaks my ability to use entire columns and have entries correspond properly....
2
2354
by: Matthew Wilson | last post by:
I want to parse an html file and extract my router's IP address. I wrote this code and I have python 2.3 installed: #! /usr/bin/env python import HTMLParser class HP(HTMLParser.HTMLParser): def handle_starttag(self, tag, data):
4
3338
by: Kevin T. Ryan | last post by:
Hi all - I'm somewhat new to python (about 1 year), and I'm trying to write a program that opens a file like object w/ urllib.urlopen, and then parse the data by passing it to a class that subclasses HTMLParser.HTMLParser. On the web page, however, there is javascript - and I think that is causing an error in parsing the data. Here's the error: Traceback (most recent call last): File "<stdin>", line 1, in ?
8
2216
by: Lawrence D'Oliveiro | last post by:
I've been using HTMLParser to scrape Web sites. The trouble with this is, there's a lot of malformed HTML out there. Real browsers have to be written to cope gracefully with this, but HTMLParser does not. Not only does it raise an exception, but the parser object then gets into a confused state after that so you cannot continue using it. The way I'm currently working around this is to do a dummy pre-parsing run with a dummy...
1
1886
by: Kenneth McDonald | last post by:
I'm writing a program that will parse HTML and (mostly) convert it to MediaWiki format. The two Python modules I'm aware of to do this are HTMLParser and htmllib. However, I'm currently experiencing either real or conceptual difficulty with both, and was wondering if I could get some advice. The problem I'm having with HTMLParser is simple; I don't seem to be getting the actual text in the HTML document. I've implemented the do_data...
1
1427
by: Just Another Victim of the Ambient Morality | last post by:
HTMLParser is behaving in, what I find to be, strange ways and I would like to better understand what it is doing and why. First, it doesn't appear to translate HTML escape characters. I don't know the actual terminology but things like &amp; don't get translated into & as one would like. Furthermore, not only does HTMLParser not translate it properly, it seems to omit it altogether! This prevents me from even doing the translation...
8
8571
by: jonbutler88 | last post by:
Just writing a simple website spider in python, keep getting these errors, not sure what to do. The problem seems to be in the feed() function of htmlparser. Traceback (most recent call last): File "spider.py", line 38, in <module> s.crawl(site) File "spider.py", line 30, in crawl self.parse(url) File "spider.py", line 21, in parse
3
2120
by: globalrev | last post by:
tried all kinds of combos to get this to work. http://docs.python.org/lib/module-HTMLParser.html from HTMLParser import HTMLParser class MyHTMLParser(HTMLParser):
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.