I have the problem that with the link below, I get 15 seperate elements of clubs the player played for instead of one element in the list, that indicates that the player changed clubs and played for two different clubs but during the same period.
url = 'https://www.transfermarkt.ch/emre-can/verletzungen/spieler/119296'
response = requests.get(url, headers={'User-Agent': 'Custom5'})
print(response.status_code)
injury_data = response.text
soup = BeautifulSoup(injury_data, 'html.parser')
table = soup.find(id="yw1")
to get the clubs the player played for I did the following:
teamlist = []
for item in table.select('img', class_='tiny_wappen'):
team_list.append(item.get('alt'))
this leads to the following result:
['Borussia Dortmund',
'Borussia Dortmund',
'Borussia Dortmund',
'Juventus Turin',
'Borussia Dortmund',
'Juventus Turin',
'Juventus Turin',
'Juventus Turin',
'FC Liverpool',
'FC Liverpool',
'FC Liverpool',
'FC Liverpool',
'FC Liverpool',
'FC Bayern München',
'FC Bayern München II']
But what I want in the end ist the following:
['Borussia Dortmund',
'Borussia Dortmund',
'Borussia Dortmund',
'Juventus Turin / Borussia Dortmund',
'Juventus Turin',
'Juventus Turin',
'Juventus Turin',
'FC Liverpool',
'FC Liverpool',
'FC Liverpool',
'FC Liverpool',
'FC Liverpool',
'FC Bayern München',
'FC Bayern München II']
in the end, I want 14 elements in the team list instead of 15, indicating that during certain periods the player was changing the clus / was playing for two clubs.
I tried the following:
teams = ['/'.join([i.get("alt") for i in item.find_all_next('a') if i.get("alt")]) for item in table.select('img', class_='tiny_wappen')
but I received a list with empty entries and it didn't work.