Im converting some python scripts that uses regex to exract contents from a html output to libxml2, but since im starting at this, a little help would be apreciated.
how i can extract the values from “working directory” , “Packages/Updates” , and “Java Data Model” of the example bellow using lxml?
<tr>
<script>writeTD("row");</script>
<td class="oddrow"><nobr>Working Dir</nobr></td>
<script>writeTD("rowdata-l");</script>
<td class="oddrowdata-l">/serves/test_servers</td>
</tr>
<script>swapRows();</script>
<tr>
<script>writeTD("row");</script>
<td class="evenrow"><nobr>Packages/Updates</nobr></td>
<script>writeTD("rowdata-l");</script>
<td class="evenrowdata-l"><a href="updates.dsp">View</a></td>
</tr>
<script>swapRows();</script>
<tr>
<script>writeTD("row");</script>
<td class="oddrow"><nobr>Java Data Model</nobr></td>
<script>writeTD("rowdata-l");</script>
<td class="oddrowdata-l">64-bit</td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>
Thanks in advance.
Using the HTML you posted as
content,yields
This line does most of the work:
It uses the
xpath()method to search for all<td>tags. It uses thetext_content()method to extract the associated text.zip(*[tds]*2)is the grouper idiom to iterate overtdsin pairs:Note that this assumes that
<td>labels and values follow each other alternately.