I'm looking to grab a url that begins with http:// or https:// from a textfile that also contains other unrelated text and transfer it to another file/list.
def test():
with open('findlink.txt') as infile, open('extractlink.txt', 'w') as outfile:
for line in infile:
if "https://" in line:
outfile.write(line[line.find("https://"): line.find("")])
print("Done")
The code currently does nothing.
Edit: I see this is being negatively voted like usual, is there anything I can add here?
This is not a duplicate, please re-read carefully.
outfile.write(line[line.find("https://"): line.find("")])?lorem ipsum https://stackoverflow.com/questions/54543095/search-and-extract-a-url-from-a-text-file dolor sit ametThere may or may not be text written after the URL soline.find(" ")would not be useful here.line.find("")this returns0that will completely mess up the slice. use re