I want to retrieve the list of games played in the FIDE archives (e.g. https://ratings.fide.com/view_source.phtml?code=272077). I manage very well to get all the columns, but to know which player was white or black, I must also get the image which is on the same line as the games (<img align="absbottom" border="0" src="/imga/clr_bl.gif"/> for blacks and <img align="absbottom" border="0" src="/imga/clr_wh.gif"/> for whites. Problem, when I try to set the player variable to 1 for white and 0 for black, my two if conditions don't work(I also tried with if in, it doesn't work either). Here is the code:
for row in rows:
picture = row.find_all('img')
print("loop")
cols = row.find_all('td')
cols = [ele.text.strip() for ele in cols]
cols.append(picture)
data.append([ele for ele in cols if ele])
for row in data:
if "ID" and "Name" in row:
continue
if 'Round' and 'Opp. name' in row:
continue
if "Game" in row:
tempdata = {
"ID" : row[0],
"Fed" : row[2],
"Rating" : row[3]
}
continue
if '<img align="absbottom" border="0" src="/imga/clr_wh.gif"/>' == picture[0]:
player = 1
print("player is white")
elif '<img align="absbottom" border="0" src="/imga/clr_bl.gif"/>' == picture[0]:
player = 0
print("player is black")
else:
player = 1
print(picture)
print("an error occured")
print(player)
I get
[<img align="absbottom" border="0" src="/imga/clr_bl.gif"/>]
an error occured
1
[<img align="absbottom" border="0" src="/imga/clr_bl.gif"/>]
an error occured
1
[<img align="absbottom" border="0" src="/imga/clr_bl.gif"/>]
an error occured
1
[<img align="absbottom" border="0" src="/imga/clr_bl.gif"/>]
an error occured
and so on.