Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to extract the domain for example: (http: //www.example.com/example-page, http ://test.com/test-page) from a list of websites in an excel sheet and modify that domain to give its url (example.com, test.com). I have got the code part figured put but i still need to get these commands to work on excel sheet cells in a column automatically.

Python
>>> url = ("http://www.example.com")
>>> domain = url.split("http://")[-1].split("/")[0]
>>> print(domain)
    www.example.com
>>> url_2 = ("http://example.com")
>>> domain_2 = url_2.split("http://")[-1].split('/')[0]
>>> print(domain_2)
    example.com
>>> 
>>> #Now to remove www. from the first one
>>> 
>>> domain_without_w3 = domain.split("www.")[-1]
>>> print(domain_without_w3)
    example.com
>>> 
>>> # both the commands would have to beexceuted on all the
>>> # values in a coloumn to extract the domain
>>> # , So here I execute the second
>>> # command too on the second url.
>>> 
>>> domain_2_without_w3 = domain_2.split("www.")[-1]
>>> print(domain_2_without_w3)
    example.com
>>> 
>>> #Ok so how do i do these to commands on a list of urls in a column
>>> # in excel automatically. That's My question.
>>> #I am sorry if anything in here looks stupid or absurd
>>> #I literally learned python 2 days ago.


What I have tried:

I tried using csv python module to create a loop.
Posted
Updated 9-Jun-19 22:13pm

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900