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=""
コードは、html テーブルから csv ファイルを作成しています。これをコーディングするためのより良い、またはより効率的な方法はありますか? 私はhtmlパーサーを探していません。