I am trying to scrape MLB lineups from this link: https://www.baseballpress.com/lineups/2022-08-04 using Python. However, when I run the code below, it pulls the data into a dataframe, with the away teams in the "first_lineup" column and the home teams in the "second_lineup" column. The issue is that when it pulls the data into a the dataframe, it does not pull everyone. Attached are screenshots of the data frame and of the website. If anyone could help explain the issue, that would be great! Thanks.


import requests
import pandas as pd
from bs4 import BeautifulSoup
url = "https://www.baseballpress.com/lineups/2022-08-04"
def get_names(item):
try:
player_name = item.get('data-razz').split("/")[-2].replace("+"," ")
except IndexError: player_name = ""
return player_name
r = requests.get(url)
soup = BeautifulSoup(r.text,'lxml')
first_lineup = [get_names(item) for item in soup.select(".col--min:nth-of-type(1) > a.player-link, [class$='col--min']:nth-of-type(1) .player > a.player-link")]
second_lineup = [get_names(item) for item in soup.select(".col--min:nth-of-type(2) > a.player-link, [class$='col--min']:nth-of-type(2) .player > a.player-link")]
df = pd.DataFrame({"first_lineup":first_lineup,"second_lineup":second_lineup})
df.to_csv("baseballpress.csv", encoding='utf-8', index=False)
print(df)
