import re
fr=open("test.html",'r')
i,j,tablestart=0,0,0
str=""
p=re.compile("<td.*?>(.*?)<\/td>")
for line in fr:
if "<table" in line:
tablestart=1
elif "</table>" in line and tablestart==1:
j,tablestart=0,0
m=p.search(line)
if m and tablestart==1:
str+='"' + m.group(1) + '"' + ","
if "</tr>" in line and tablestart==1:
print(str)
str=""
The code is creating csv file from html table. Is there a better or more efficient way to code this? I'm not looking for any html parsers.