0

Hello

I have a code that's going to search multiples times a string as long as the string appears in a .txt file and I'm obligated to use this form to search the strings : data[data.index('"display_url":"'):data.index('","display_resources":')+1].

  • How can I make it run and add the string that it find to my list (as long as it appears in the .txt) ?

The real part of the code :

urls = []  
g = open('tet.txt','r') data=''.join(g.readlines())
dat = (data[data.index('"display_url":"'):data.index('","display_resources":')+1])
urls.append(dat) 
g.close() 
print(urls)

Thanks for your help

Hidd
  • 23
  • 6
  • This question may be helpful to reference: https://stackoverflow.com/questions/4664850/find-all-occurrences-of-a-substring-in-python – Collin Mar 27 '19 at 20:44
  • I will try, thanks. I will make it the answer if I make it work. – Hidd Mar 27 '19 at 21:40

1 Answers1

0

Alternative found here :

Find A->B strings multiples times with a while loop

Hidd
  • 23
  • 6