How do I parse the string?

hello

There is a string below.
FTP://21.105.28.15/abc/test1.txt
Cut this string
/abc/
I just want to get the path.

How do I parse the string?

import pymssql
conn = pymssql.connect('10.21.100.21', 'sa', 'abc', 'DBA', as_dict=False) 
cur = conn.cursor()

cur.execute('select path From table')
 
fetch = cur.fetchall()
 
for i in fetch:
	print (i) <==== FTP://21.105.28.15/abc/test1.txt (Cut this string /abc/ 
I just want to get the path.)

conn.close()

Split the string for on every / and then just remove the first 3 item, which will be the host, and if you don’t need the end/the file just remove the last element. Oh and I almost forgot, you need to join it back together, like:

x = "FTP://21.105.28.15/abc/test1.txt"
x = x.split("/")[3:]
x = "/".join(x)
print(x)

I would use urllib.parse — Parse URLs into components — Python 3.8.18 documentation