HTMLParser problem

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

    #1

    HTMLParser problem

    I've fed some data to the HTML parser constructed by myself. Here is the
    beginning of the content of the fed data:
    =====
    <!doctype html public "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html><head><me ta http-equiv="content-type" content="text/html;
    charset=ISO-8859-1"><link rel="stylesheet "
    href="http://us.i1.yimg.com/us.yimg.com/lib/s/yschx_040927.cs s" type="text/css"
    media="all">

    <![if !IE]>
    ....
    =====
    however, when "<![if !IE]>" is encountered, I found that handle_data() is called
    but not handle_decl(), (since I've let the function handle_decl to print sth on
    the screen, but nothing happened) and the following error is displayed:

    .......
    HTMLParser.HTML ParseError: unknown declaration: 'if !IE', at line 4, column 1

    May I ask why such error is raised? Thanks in advance!
  • Richard Brodie

    #2
    Re: HTMLParser problem


    "Valkyrie" <valkyrie@cuhk. edu.hk> wrote in message news:1100610863 .75889@eng-ser4...
    [color=blue]
    > <![if !IE]>
    >
    > HTMLParser.HTML ParseError: unknown declaration: 'if !IE', at line 4, column 1
    >
    > May I ask why such error is raised?[/color]

    HTMLParser isn't very forgiving of bad HTML; you feed it syntactically invalid HTML,
    it tends to give you errors. That includes Microsoft only extensions like <![if !IE.
    Unless you know you have known valid sources it may be best to use one of
    the forgiving parsers: Beautiful Soup, UTidylib, libxml etc.. (see many past discussions).
    Uche's article: http://www.xml.com/pub/a/2004/09/08/pyxml.html may be of interest.


    Comment

    • Valkyrie

      #3
      Re: HTMLParser problem

      Thank you. That means there is no way to deal with it using simple python
      built-in functions?


      Richard Brodie wrote:
      [color=blue]
      > "Valkyrie" <valkyrie@cuhk. edu.hk> wrote in message news:1100610863 .75889@eng-ser4...
      >
      >[color=green]
      >><![if !IE]>
      >>
      >>HTMLParser.HT MLParseError: unknown declaration: 'if !IE', at line 4, column 1
      >>
      >>May I ask why such error is raised?[/color]
      >
      >
      > HTMLParser isn't very forgiving of bad HTML; you feed it syntactically invalid HTML,
      > it tends to give you errors. That includes Microsoft only extensions like <![if !IE.
      > Unless you know you have known valid sources it may be best to use one of
      > the forgiving parsers: Beautiful Soup, UTidylib, libxml etc.. (see many past discussions).
      > Uche's article: http://www.xml.com/pub/a/2004/09/08/pyxml.html may be of interest.
      >
      >[/color]

      Comment

      • Dirk-Jan C. Binnema

        #4
        Re: HTMLParser problem

        On Tue, 16 Nov 2004 22:14:33 +0800, Valkyrie <valkyrie@cuhk. edu.hk> wrote:[color=blue]
        > Thank you. That means there is no way to deal with it using simple python
        > built-in functions?[/color]

        Well, you can always preprocess your HTML by replacing dubious
        constructs. It's ugly but it works. You might even do something smart
        and replace thing back after processing.

        Good luck,
        Dirk.

        -------------------------------------
        Dirk-Jan C. Binnema (djcb)
        mail: djcb [at] djcbsoftware [dot] nl
        blog: www.djcbsoftware.nl/ChangeLog
        im : djcb@jabber.org
        -------------------------------------

        Comment

        Working...