I have the following code:
pattern = re.compile(r"^\s\s<strong>.*</strong>$")
matches = []
with open(r"spotifycharts.html", "rt") as current_file:
content = current_file.read()
for line in content:
matches = findall(pattern, line)
print(matches)
I have checked that the pattern works and matches with the strings found in the html file. However, the findall() function still returns an empty list. Is there something I've done wrong here?
EDIT: An error was pointed out and I fixed it. The matches list still is empty once the code is run.
pattern = re.compile(r"^\s\s<strong>.*</strong>$")
matches = []
with open(r"spotifycharts.html", "rt") as current_file:
content = current_file.read()
for line in content:
if findall(pattern, line) != []:
matches.append(findall(pattern, line))
print(matches)
Here is less code which produces the same problem. Hope this helps
matches = []
with open(r"spotifycharts.html", "rt") as current_file:
content = current_file.read()
matches = findall("^\s\s<strong>.*</strong>$", content)
print(matches)
Source HTML: view-source:https://spotifycharts.com/regional/au/daily/latest