I am having trouble with saving a file using Python on windows.
Here's the URL variable that stores the URL:
my_url = "https://example.com/some-page"
I want to remove the "https:" part and all the "/" from this string. This is what I tried:
filename = my_url.replace('https://', '')
filename = filename.replace('http://', '')
filename = filename.replace('/', '|') + ".txt"
I want to remove these characters as windows doesn't allow : and / characters as a file name.
The error that I am getting is:
Traceback (most recent call last):
File "123.py", line 28, in <module>
f = open(filename, "w")
OSError: [Errno 22] Invalid argument: 'example.com|some-page.txt'
I want to do this with multiple URLs so even though the actual link uses https I tried to remove the http too.
|in the file name so you'll need a different replacement character.