Comment obtenir un des éléments html avec python lxml

J'ai ce code html:

<table>
 <tr>
  <td class="test"><b><a href="">aaa</a></b></td>
  <td class="test">bbb</td>
  <td class="test">ccc</td>
  <td class="test"><small>ddd</small></td>
 </tr>
 <tr>
  <td class="test"><b><a href="">eee</a></b></td>
  <td class="test">fff</td>
  <td class="test">ggg</td>
  <td class="test"><small>hhh</small></td>
 </tr>
</table>

- Je utiliser ce code Python pour extraire tous les <td class="test"> avec lxml module.

import urllib2
import lxml.html

code   = urllib.urlopen("http://www.example.com/page.html").read()
html   = lxml.html.fromstring(code)
result = html.xpath('//td[@class="test"][position() = 1 or position() = 4]')

Il fonctionne bien! Le résultat est:

<td class="test"><b><a href="">aaa</a></b></td>
<td class="test"><small>ddd</small></td>


<td class="test"><b><a href="">eee</a></b></td>
<td class="test"><small>hhh</small></td>

(donc la première et de la quatrième colonne de chaque <tr>)
Maintenant, j'ai de l'extrait:

aaa (le titre du lien)

ddd (texte entre <small> tag)

eee (le titre du lien)

hhh (texte entre <small> tag)

Comment ai-je pu extraire ces valeurs?

(le problème c'est que je dois supprimer <b> balise et d'obtenir le titre de l'ancre sur la première colonne et supprimer <small> étiquette sur la quatrième colonne)

Merci!

OriginalL'auteur Damiano | 2010-05-10