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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:28:51+00:00 2026-05-12T16:28:51+00:00

I have a link such as http://www.techcrunch.com/ and I would like to get just

  • 0

I have a link such as http://www.techcrunch.com/ and I would like to get just the techcrunch.com part of the link. How do I go about this in python?

  • 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-12T16:28:51+00:00Added an answer on May 12, 2026 at 4:28 pm

    Getting the hostname is easy enough using urlparse:

    hostname = urlparse.urlparse("http://www.techcrunch.com/").hostname
    

    Getting the “root domain”, however, is going to be more problematic, because it isn’t defined in a syntactic sense. What’s the root domain of “www.theregister.co.uk”? How about networks using default domains? “devbox12” could be a valid hostname.

    One way to handle this would be to use the Public Suffix List, which attempts to catalogue both real top level domains (e.g. “.com”, “.net”, “.org”) as well as private domains which are used like TLDs (e.g. “.co.uk” or even “.github.io”). You can access the PSL from Python using the publicsuffix2 library:

    import publicsuffix
    import urlparse
    
    def get_base_domain(url):
        # This causes an HTTP request; if your script is running more than,
        # say, once a day, you'd want to cache it yourself.  Make sure you
        # update frequently, though!
        psl = publicsuffix.fetch()
    
        hostname = urlparse.urlparse(url).hostname
    
        return publicsuffix.get_public_suffix(hostname, psl)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume I have the link http://www.somesite.com/file.aspx?a=1&b=2 And now I want to remove all the
I am trying to pass parameters to a URL which looks like this: http://www.foobar.com/foo?imageurl=
I have html page with 2 links like <a href=http://www.w3schools.com/>Visit W3Schools</a> <a href=http://www.w4schools.com/>Visit W4Schools</a>
Okay.. so basically, say we have a link: $url = http://www.site.com/index.php?sub=Mawson&state=QLD&cat=4&page=2&sort=z; Basically, I need
I'm trying to get a users ID from a string such as: http://www.abcxyz.com/123456789/ To
I have such a link in JSP page with encoding big5 http://hello/world?name=婀ㄉ And when
I have an image, and I would like to make the image link to
This next challenge of mine involves jqtransform which can be found here http://www.dfc-e.com/metiers/multimedia/opensource/jqtransform/ I
I'm trying to do CSS Sprites, such as: http://www.alistapart.com/articles/sprites My menu is going to
I looked at this site example: http://www.codesampler.com/dx9src/dx9src_6.htm But the code is rather weird: it

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.