Text over multiple lines

Nelson Minar nelson at monkey.org
Sun Jun 20 19:22:53 CEST 2004

Rigga <Rigga at hasnomail.com> writes:
> I am using the HTMLParser to parse a web page, part of the routine I need
> to write (I am new to Python) involves looking for a particular tag and
> once I know the start and the end of the tag then to assign all the data
> in between the tags to a variable, this is easy if the tag starts and ends
> on the same line however how would I go about doing it if its split over
> two or more lines?

I often have variants of this problem too. The simplest way to make it
work is to read all the HTML in at once with a single call to
file.read(), and then use a regular expression. Note that you probably
don't need re.MULTILINE, although you should take a look at what it
means in the docs just to know.

This works fine as long as you expect your files to be relatively
small (under a meg or so).

More information about the Python-list mailing list