<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
We have had great success with PyQuery for getting API access to XML
data:<br>
<br>
<a class="moz-txt-link-freetext" href="http://pypi.python.org/pypi/pyquery">http://pypi.python.org/pypi/pyquery</a><br>
<pre class="moz-signature" cols="72">--------------------------------------
Randy Syring
Intelicom
502-644-4776
"Whether, then, you eat or drink or
whatever you do, do all to the glory
of God." 1 Cor 10:31</pre>
<br>
<br>
Tim Roberts wrote:
<blockquote cite="mid:4C1A7249.7020204@probo.com" type="cite">
<pre wrap="">On 6/17/2010 11:09 AM, Mauricio Martinez Garcia wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hi, how can parse an HTML String.
I need parse next Line :
'<FIELD><NAME>BSCS
status</NAME><TYPE>string</TYPE><VALUE>none</VALUE></FIELD><FIELD><NAME>TopCre_life</NAME><TYPE>integer</TYPE><VALUE>0</VALUE></FIELD>'
</pre>
</blockquote>
<pre wrap=""><!---->
That's not HTML. It's XML. You CAN parse this with the SGMLParser
(since XML is a variant of SGML), but you might consider whether you
would be better served using xmllib, or even xml.sax.
</pre>
<blockquote type="cite">
<pre wrap="">Result of program its:
bash-3.1$ ./pruebasDOM.py
['BSCS status']
['string']
['none']
['TopCre_life']
['integer']
['0']
I can't pass the data to one dict() or []. I need all values, ['BSCS
Status', 'string', 'none', 'TopCre_life', 'integer', '0']
That i can do?
</pre>
</blockquote>
<pre wrap=""><!---->
Of course. Just change your ParserHTML class to create a list in "def
__init__", then append the values that you get to the list instead of
printing them. So, for example:
class ParserHTML(SGMLParser):
def __init__(self):
SGMLParser.__init__(self)
self.results = []
...
def handle_data(self, data):
...
self.results.append(data)
...
if __name__ == '__main__':
...
p = ParserHTML()
p.feed(node)
print p.results
</pre>
</blockquote>
</body>
</html>