Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8329951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:57:52+00:00 2026-06-09T01:57:52+00:00

Im converting some python scripts that uses regex to exract contents from a html

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T01:57:54+00:00Added an answer on June 9, 2026 at 1:57 am

    Using the HTML you posted as content,

    import lxml.html as LH
    doc = LH.fromstring(content)
    tds = (td.text_content() for td in doc.xpath('//td'))    
    for td, val in zip(*[tds]*2):
        if td in ("Working Dir", "Java Data Model"):
            print(td,val)
    

    yields

    ('Working Dir', '/serves/test_servers')
    ('Java Data Model', '64-bit')
    

    This line does most of the work:

    tds = (td.text_content() for td in doc.xpath('//td'))
    

    It uses the xpath() method to search for all <td> tags. It uses the text_content() method to extract the associated text.

    zip(*[tds]*2) is the grouper idiom to iterate over tds in pairs:

    for td, val in zip(*[tds]*2):
        print(td,val)
    

    Note that this assumes that <td> labels and values follow each other alternately.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am converting some code from another language to python. That code reads a
I'm converting some c code to python. Can someone convert this for loop from
Some code I am inheriting uses Python's psycopg2 module to return mxDateTime objects from
I am converting some c code to python. I am wondering that is there
While converting a project from Python to C#, I found some interesting differences in
I need some help converting decimal to hex with NO functions on python. I'm
Possible Duplicate: Converting XML to JSON using Python? I'm doing some work on App
I'm converting some services from Apache SOAP to Axis2, so the Java service classes
I have been tasked with converting some scripts referencing an Informix database to be
I am having a problem converting one of my company's scripts from csh to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.