I would to scrape tables with the headers contains a word
import requests
from bs4 import BeautifulSoup
url ='https://www.transfermarkt.com/juventus-turin/alletransfers/verein/506'
headers = {
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0"
}
content = requests.get(url, headers=headers)
soup = BeautifulSoup(content.text, 'html.parser')
h2 = soup.find_all(lambda elm: elm.name == 'h2' and 'Departures' in elm.text)
for h in h2:
table = h.find_next('table')
print(table)
With this code I get 'Arrivals' tables. How can I get only the Departures tables to work on?