24 Nisan 2010 Cumartesi

python xml parser - easy

#! /usr/bin/python

import os
import urllib
from sgmllib import SGMLParser


class urlParser(SGMLParser):
tags
= {}
pointer
=""

def unknown_starttag(self, tag, attrs):
self.pointer
= tag

def handle_data(self, data):
if data.strip().__len__>0:
self.tags[self.pointer]
= data


parser
= urlParser()
uhandle
= urllib.urlopen("http://192.168.1.18/proxy/touchGetMail.php")

res
= uhandle.read()
uhandle.close()

parser.feed(res)

print "name::"+ parser.tags['name']
print "email::"+ parser.tags['email']

Hiç yorum yok:

Yorum Gönder