-2

I'm trying to learn Python and I have one question.

I want to take all html links from a webpage source file and append them to a list. For example I want to search the string for every instance of ../lyrics.*html and insert those instances in a list. The result would be a list of html links such as this:

["../lyrics/steviewonder/lovesinneedoflovetoday.html", "../lyrics/steviewonder/haveatalkwithgod.html", "../lyrics/steviewonder/villageghettoland.html"] 

Help is much appreciated! Thank you!

1 Answers1

1

You can use a regular expression to search for such strings.

import re

re.match(r"(.*)/lyrics/(.+?)html", line)
clabiak
  • 26
  • 1