HTMLParser's start_tag method never called ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ychaouche

    #1

    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

  • Diez B. Roggisch

    #2
    Re: HTMLParser's start_tag method never called ?

    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

    Comment

    • ychaouche

      #3
      Re: HTMLParser's start_tag method never called ?

      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

      Comment

      • Leif K-Brooks

        #4
        Re: HTMLParser's start_tag method never called ?

        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"

        Comment

        Working...