3

I currently have a list of URLs

http://www.website.com/dynamic/download.ashx?id=123/12/12345
http://www.website.com/dynamic/download.ashx?id=12/121/123451
http://www.website.com/dynamic/download.ashx?id=1/1233/123

I am looking to create a new list replacing the / with _ and stripping the URL. Creating a new list:

123_12_12345
12_121_123451
1_1233_123

I have removed the URL by splitting

for z in columns['location']:
    print z.split('=')[1:]enter code here
    stripped.append(z.split('=')[1:])

help to replace / with _ would be appreciated. cheers!

AdianDes
  • 147
  • 1
  • 1
  • 8
  • Possible duplicate of [Python replace multiple strings](http://stackoverflow.com/questions/6116978/python-replace-multiple-strings) – sebastianf182 Mar 15 '17 at 03:32

2 Answers2

1

This will split about =, grab the second part and then replace / with _.

urls = ["http://www.website.com/dynamic/download.ashx?id=123/12/12345",
        "http://www.website.com/dynamic/download.ashx?id=12/121/123451",
        "http://www.website.com/dynamic/download.ashx?id=1/1233/123"]

for url in urls:
    print(url.split("=")[1].replace("/","_"))
Neil
  • 14,063
  • 3
  • 30
  • 51
0
newink = a.split('=')[0] + a.split('=')[1].replace('/','_')

Then loop for each link to convert it