ich versuche gerade mit lxml.html Tabellenzellen einer HTML-Seite auszulesen.
Den Element Tree hole ich mit:
Code: Alles auswählen
import urllib
from lxml.html import fromstring
def get_site(url):
content = urllib.urlopen(url).read()
doctree = lxml.html.fromstring(content)
doctree.make_links_absolute(url)
Code: Alles auswählen
...
<table class="detailTable" cellspacing="0">
<tbody>
<tr class="odd">
<td class="timeDetail borderTopodd">19:17</td>
<td class="odvDetail borderTopodd">Hier steht ein Text</td>
...
<td class="motDetail borderTopodd" rowspan="2">Hier steht auch ein Text</td>
...
</tr>
...
Als regulären Ausdruck wollte ich z.B. "(odd|even)" und "timeDetai\\w*" verwenden, jedoch kommen die Funktionen .find_class() und .findall() mit regulären Ausfrücken als Argument nicht zurecht.
Code: Alles auswählen
for table in doctree.find_class('odd'):
retime = re.compile('.//td[@class="odvDetai\\w*"]')
for item in table.findall('.//td[@class="timeDetail"]'): #tr[@class="odd"]/
print type(item)
time = item.text
print time
for item in table.findall('.//td[@class="odvDetail"]'):
location = item.text
print location
for item in table.findall('.//td[@class="modDetail"]'):
description = item.text
print description