Приведенный ниже код выполняется без ошибок, но для каждой итерации for-l oop существуют повторяющиеся значения. Я пытался исправить эту ошибку, но не могу. Мне действительно нужна твоя помощь.
import requests, json
conditions = []
list1 = []
list2 = []
playlist= []
for line in lines:
if '<A HREF="/1920' in line:
parts = line.split("\"")
url = base + parts[1]
#print(url)
r = requests.get(url)
teamlines = r.text.split("\n")
parse = False
parse1 = False
tn =0
rc = 0
cc = 0
aa=0
bb=0
d ={}
for teamline in teamlines:
if '<table width="856" border=1 cellpadding=1 cellspacing=1 class="chssmallreg">' in teamline:
tn+=1
if '<tr valign=top align=right>' in teamline:
rc +=1
cc = 0
if '<td ' in teamline:
cc+=1
if cc == 0 and tn == 1 and '</td>' in teamline:
if '<td> </td>' != teamline:
playernumber = teamline.split('<td>')[1].split('</td>')[0]
list1.append(playernumber)
players = {}
players['player number'] = playernumber
if tn == 1 and cc ==1:
if '<td colspan=3 align=left>Bench</td>' != teamline:
playername = teamline.split('<td align=left><strong>')[1].split('</strong></td>')[0]
list2.append(playername)
players['player name']= playername
playlist.append(players)
if '<FONT SIZE=+1 FACE="Verdana,Arial,Helvetica"><B><I> ' in teamline:
team_name = teamline.split('<FONT SIZE=+1 FACE="Verdana,Arial,Helvetica"><B>
<I> ')[1].split('(Men)<BR>')[0]
if '<td valign=top bgcolor="#DDDDDD"><strong>Home:</strong></td>' in teamline:
parse1= True
if '<td valign=top bgcolor="#DDDDDD"><strong>Away:</strong></td>' in teamline:
parse1= False
if '<td valign=top bgcolor="#DDDDDD">' in teamline and parse1==True:
aa+=1
if '</td>' in teamline and parse1==True:
bb+=1
if parse1:
if '<td valign=top bgcolor="#DDDDDD"> ' in teamline:
Situational_Records_Conference = teamline.split('<td valign=top
bgcolor="#DDDDDD">')[1].split('</td>')[0]
Situational_Records_Conference = Situational_Records_Conference.split('-')
d['team'] = {}
d['team']['team name'] = team_name
d['team']['team wins'] = Situational_Records_Conference [0]
d['team']['team losses'] = Situational_Records_Conference [1]
d['team']['team ties'] = Situational_Records_Conference [2]
d['team']['team players'] = playlist
conditions.append(d)
print(json.dumps(conditions))