Python Forum
.txt return specific lines or strings
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
.txt return specific lines or strings
#7
I got it. Thanks

import re
# Target file to search
target_file = 'randomtextfile.txt'

# Open the target file in Read mode
target_open = open(target_file, 'r')

# Read the file
read_file = target_open.read()

# No idea what this does.......
urls = re.findall('(?:(?:https?|ftp):\/\/)?[\w/\-?=%.]+\.[\w/\-?=%.]+', read_file)

# Print urls in list one at a time. Top to bottom.
for i in urls:
    print(i)
Reply


Messages In This Thread
.txt return specific lines or strings - by s_o_what - Feb-06-2019, 02:53 AM
RE: .txt return specific lines or strings - by s_o_what - Feb-08-2019, 02:34 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I extract specific lines from HTML files before and after a word? glittergirl 1 5,123 Aug-06-2019, 07:23 AM
Last Post: fishhook

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020