[Tutor] HTML Parsing

Andreas Kostyrka andreas at kostyrka.org
Mon Apr 21 20:29:43 CEST 2008


eeck.

Not that I advocate parsing files by line, but if you need to do it:

lines = list(file)[16:]

or

lines_iter = iter(file)
zip(lines_iter, xrange(16))
for line in lines_iter:

Andreas

Am Montag, den 21.04.2008, 14:42 +0000 schrieb linuxian iandsd:
> Another horrid solution 
>  
>         #!/usr/bin/python
>         # line number does not change so we use that
>         # the data we're looking for does not have a (unique) close
>         tag (htmllib ????)
>         
>         import re, urllib2
>         file=urllib2.urlopen('http://10.1.2.201/server-status')
>         n=0
>         for line in file:
>          n=n+1
>          if n==16:
>           print re.sub('requests.*','',line)[4:].strip()
>          elif n==17:
>           print re.sub('requests.*','',line)[4:].strip()
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://mail.python.org/pipermail/tutor/attachments/20080421/23e53f62/attachment.pgp 


More information about the Tutor mailing list