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 8330747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:12:33+00:00 2026-06-09T02:12:33+00:00

How I can do the following block of code from perl to python? while

  • 0

How I can do the following block of code from perl to python?

while ($content2 =~ m{services</B></TD>\s<TD>\s<TABLE>\s<TR>(.*?)</TABLE>}gs) {
  my $service=$1
  print " service : $1\n";
}

The full code have more regex outputs than that, but with that example I’m able to proceed with the conversion.

  • 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-09T02:12:35+00:00Added an answer on June 9, 2026 at 2:12 am

    If i’m reading your regex right, you have a table with a single row (and no data cell) inside a table-data cell. What kind of abomination are you cooking up here?

    In python you’d use lxml for this. It’s a real parser, so it won’t fail when whitespace or casing or other unrelated structure of the document changes. It’s not a part of the standard library, but it’s one of (if not /the/) most-installed libraries on pypi.

    abominable_html = '''
    <html>
    <table><tr><td>services</B></TD>
        <TD>
            <TABLE> <TR>Interesting stuff!</TABLE>
    '''
    
    from lxml.html import fromstring
    doc = fromstring(abominable_html)
    
    # These are equivalent, for demonstration purposes.
    print doc.xpath('//table/tr/td/table/tr/text()')[0]
    print doc.xpath('//table//table/tr')[0].text
    

    As you can see, it deals with questionable html admirably.


    If you need match the “services” text, you can add a condition like so:

    print doc.xpath('//table[./tr/td="services"]//table/tr')[0].text
    

    Here are some good xpath references:

    • http://www.w3.org/TR/xpath/#path-abbrev (just read the examples)
    • http://our.umbraco.org/media/upload/0562fd58-c6db-4fa8-a432-68b28f11c3f2/rs/7x1B0.gif
    • http://zvon.org/comp/r/ref-XPath_1.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code block for validation in PHP and I can't figure
I can not get the right result from the following code block: object ob
If use MongoRepository, You can have following code: @Repository public interface UserRepo extends MongoRepository<User,
Possible Duplicate: Foreach can throw an InvalidCastException? Consider the following block of code public
I currently have the following block of SQL 2005 code. What I need to
In the following block of code, I am trying to print the properties whose
In C#, the following code (from this page) can be used to lazily instantiate
I can't see why this doesn't work. The following code block throws a warning
I can call a macro from within my add-in with the following code: Application.Run(MACRO_NAME);
I have the following sample code #!/usr/bin/perl use strict; use warnings; my $b =

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.