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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:15:39+00:00 2026-05-28T07:15:39+00:00

By URL remapping, I mean changing all the hrefs and srcs and actions and

  • 0

By URL remapping, I mean changing all the “href”s and “src”s and “action”s and … inside an actual HTML doc.

Are there any python libraries to do this type of URL remapping?

On a python web server app (based on tornado) I want to be able to modify the HTML code that I server based on some conditions.

Imagine I read this HTMLs off disk but I need to replace all the links and … to point to this subdomain/domain and path or that one.

Lets say I dont want to use templates to rewrite all the HTML that I have on disk (to put tags inside and replace the tags on run time) also lets for the sake of simplicity imagine I have no external links (like I never link to google.com [that requires conditional remapping]).

  • 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-05-28T07:15:40+00:00Added an answer on May 28, 2026 at 7:15 am

    As far as i know, there is no such library, but you can use some html parsing library like lxml or BeautifulSoup together with urlparse standard Python moule. I prefer using lxml and XPath.

    For example, we have saved StackOverflow page as doc.html, and we want to do something with nodes which contains href, src, actions:

    import urlparse
    
    import lxml.html
    
    
    with open('doc.htm') as f:
        doc = lxml.html.parse(f)
    
    for el in doc.xpath('//*[@href | @src | @action]'):
        tag = el.tag
        href = el.get('href', '')
        if not href:
            continue
    
        # not really need to check for '/' when using urljoin, but this is just example
        if href.startswith('/'): 
            el.attrib['href'] = urlparse.urljoin('http://stackoverflow.com/', href)
    
    # then get string representation of tree back
    result = lxml.html.tostring(doc)
    

    In this example, I’m only converting relative href‘s started with ‘/’ to absolute using urlparse.urljoin, and not all elements from XPath result used. But you can customize it for your needs.

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

Sidebar

Related Questions

url.rewrite-once = ( .*\.(js|ico|gif|jpg|png|css|html)$ => $0, ^/([^?]*)(\?.*)?$ => /$1.php/$2, ) This is what I
string url = http://google.com/index.html; WebClient client = new WebClient(); Stopwatch sw = new Stopwatch();
[URL removed per my bosses request] - please see screenshot in first comment to
URL u=new URL("telnet://route-server.exodus.net"); This line is generating : java.net.MalformedURLException: unknown protocol: telnet And I
URL url = new URL(http://www.example.com/comment); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setRequestMethod(POST); Is connection.setRequestProperty(key,
URL url = new URL(http://twitter.com/statuses/update.xml); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); String cridentials =
url: http://www.pagepilot.co.uk/pp_cftest/ When posted into facebook debugger: https://developers.facebook.com/tools/debug/og/object?q=http%3A%2F%2Fwww.pagepilot.co.uk%2Fpp_cftest%2F Keeps returning a 206 Partial Response
MyRoot URL is http://Repositories/svn/ibtis/ and checkout rule is +:tags\TestReleaseHead=>. Now I have set the
string []URL = {www.facebook.com,www.orkut.com,www.yahoo.com}; Int32 result = URL.Length; SetPolicyURL( URL,result ); this is my
if url contains like this and I want to if segment1 equals something then

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.