J'utilise lxml pour l'analyse XML, mais j'utilise BeautifulSoup pour HTML. Voici une visite très rapide/brève, se terminant par une solution à votre question. J'espère que cela aide.
Python 2.6.5 (r265:79359, Mar 24 2010, 01:32:55)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from BeautifulSoup import BeautifulSoup as soup
>>> stream = open('bs.html', 'r')
>>> doc = soup(stream.read())
>>> doc.body.span
<span class="text">One</span>
>>> doc.body.span.nextSibling
u'some text1'
>>> x = doc.findAll('span')
>>> for i in x:
... print unicode(i)
...
<span class="text">One</span>
<span class="cyrillic">Мир</span>
>>> x = doc('span')
>>> type(x)
<class 'BeautifulSoup.ResultSet'>
>>> for i in x:
... print unicode(i)
...
<span class="text">One</span>
<span class="cyrillic">Мир</span>
>>> for i in x:
... print i.nextSibling
...
some text1
some text2
>>>
Voici le tutoriel: http://codespeak.net/lxml/tutorial.html Tout spécifique que vous ne comprenez pas? – Wolph
Ce lien de tutoriel est défunt. S'il vous plaît retirer. – ely