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

  • SEARCH
  • Home
  • 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 150343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:16:32+00:00 2026-05-11T09:16:32+00:00

I extract some code from a web page ( http://www.opensolaris.org/os/community/on/flag-days/all/ ) like follows, <tr

  • 0

I extract some code from a web page (http://www.opensolaris.org/os/community/on/flag-days/all/) like follows,

<tr class='build'>   <th colspan='0'>Build 110</th> </tr> <tr class='arccase project flagday'>   <td>Feb-25</td>   <td></td>   <td></td>   <td></td>   <td>     <a href='../pages/2009022501/'>Flag Day and Heads Up: Power Aware Dispatcher and Deep C-States</a><br />     cpupm keyword mode extensions - <a href='/os/community/arc/caselog/2008/777/'>PSARC/2008/777</a><br />     CPU Deep Idle Keyword - <a href='/os/community/arc/caselog/2008/663/'>PSARC/2008/663</a><br />   </td> </tr> 

and there are some relative url path in it, now I want to search it with regular expression and replace them with absolute url path. Since I know urljoin can do the replace work like that,

>>> urljoin('http://www.opensolaris.org/os/community/on/flag-days/all/', ...         '/os/community/arc/caselog/2008/777/') 'http://www.opensolaris.org/os/community/arc/caselog/2008/777/' 

Now I want to know that how to search them using regular expressions, and finally tanslate the code to,

<tr class='build'>   <th colspan='0'>Build 110</th> </tr> <tr class='arccase project flagday'>   <td>Feb-25</td>   <td></td>   <td></td>   <td></td>   <td>     <a href='http://www.opensolaris.org/os/community/on/flag-days/all//pages/2009022501/'>Flag Day and Heads Up: Power Aware Dispatcher and Deep C-States</a><br />     cpupm keyword mode extensions - <a href='http://www.opensolaris.org/os/community/arc/caselog/2008/777/'>PSARC/2008/777</a><br />     CPU Deep Idle Keyword - <a href='http://www.opensolaris.org/os/community/arc/caselog/2008/663/'>PSARC/2008/663</a><br />   </td> </tr> 

My knowledge of regular expressions is so poor that I want to know how to do that. Thanks

I have finished the work using Beautiful Soup, haha~ Thx for everybody!

  • 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. 2026-05-11T09:16:32+00:00Added an answer on May 11, 2026 at 9:16 am

    First, I’d recommend using a HTML parser, such as BeautifulSoup. HTML is not a regular language, and thus can’t be parsed fully by regular expressions alone. Parts of HTML can be parsed though.

    If you don’t want to use a full HTML parser, you could use something like this to approximate the work:

    import re, urlparse  find_re = re.compile(r'\bhref\s*=\s*('[^']*'|\'[^\']*\'|[^'\'<>=\s]+)')  def fix_urls(document, base_url):     ret = []     last_end = 0     for match in find_re.finditer(document):         url = match.group(1)         if url[0] in '\''':             url = url.strip(url[0])         parsed = urlparse.urlparse(url)         if parsed.scheme == parsed.netloc == '': #relative to domain             url = urlparse.urljoin(base_url, url)             ret.append(document[last_end:match.start(1)])             ret.append(''%s'' % (url,))             last_end = match.end(1)     ret.append(document[last_end:])     return ''.join(ret) 

    Example:

    >>> document = '''<tr class='build'><th colspan='0'>Build 110</th></tr> <tr class='arccase project flagday'><td>Feb-25</td><td></td><td></td><td></td><td><a href='../pages/2009022501/'>Flag Day and Heads Up: Power Aware Dispatcher and Deep C-States</a><br />cpupm keyword mode extensions - <a href='/os/community/arc/caselog/2008/777/'>PSARC/2008/777</a><br /> CPU Deep Idle Keyword - <a href='/os/community/arc/caselog/2008/663/'>PSARC/2008/663</a><br /></td></tr>''' >>> fix_urls(document,'http://www.opensolaris.org/os/community/on/flag-days/all/') '<tr class='build'><th colspan='0'>Build 110</th></tr> <tr class='arccase project flagday'><td>Feb-25</td><td></td><td></td><td></td><td><a href='http://www.opensolaris.org/os/community/on/flag-days/pages/2009022501/'>Flag Day and Heads Up: Power Aware Dispatcher and Deep C-States</a><br />cpupm keyword mode extensions - <a href='http://www.opensolaris.org/os/community/arc/caselog/2008/777/'>PSARC/2008/777</a><br /> CPU Deep Idle Keyword - <a href='http://www.opensolaris.org/os/community/arc/caselog/2008/663/'>PSARC/2008/663</a><br /></td></tr>' >>> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to extract some information from a web page that's contained in an
I am working to extract some content from a web page. Given below is
im trying to extract some files from a jar-file downloaded using java-webstart. below code
I'm trying to write some code to extract Exif information from a JPG. Exif
I need to take a web page and extract the address information from the
I need to extract text from any kind of web page using regex in
Given below is some HTML code corresponding to a div in a web page--
I am using Beautiful Soup to extract 'content' from web pages. I know some
I'm using Web-Harvest to extract some data from a site. Site gets a POST
I'm currently trying to extract information from a badly formatted web page. Specifically, the

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.