furas

Python - search url in text using find()

Apr 13th, 2020 (edited)
382
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # author: Bartlomiej "furas" Burek (https://blog.furas.pl)
  2. # 2020.04.13
  3.  
  4. text = "The link to your file is https://filecloud.com/12345/sample.png.html. If this link doesn't work, try https://filecloudlinks.com/12345/sample.png.html."
  5.  
  6. pos = 0
  7. start = text.find("https", pos)
  8. end   = text.find(".html", pos) + len(".html")
  9.  
  10. while start != -1 and end != -1:
  11.     print(text[start:end])
  12.  
  13.     pos = end
  14.     start = text.find("https", pos)
  15.     end   = text.find(".html", pos) + len(".html")
RAW Paste Data