DataFrame de acordo com o nome do jogador escolhido

    import requests
    from bs4 import BeautifulSoup
    import pandas as pd
    import streamlit as st
    import re
    import time

    st.title("Web Scraping MLB")


    my_bar = st.progress(0)

    for percent_complete in range(100):
    
        time.sleep(0.1)
        my_bar.progress(percent_complete + 1)


    def get_object(url):
    soup = BeautifulSoup(requests.get(url).content,'html.parser')
    return soup


    
    def get_all_summary_career(bsObject):
        
    table = [i for i in bsObject.find("div",class_ = "player-stats-summary-large")]  
    df_html = pd.read_html(str(table))[0]
    df = pd.DataFrame(df_html)
    return df


    links = []
    for i in range(1,7):
    
    url = "https://www.mlb.com/stats" + "/?page" + "=" + str(i)
    links.append(url)
 
    lista_players = []
    for item in links:
    
    result = requests.get(item).content
    bsObject =  BeautifulSoup(result,'html.parser')
    
    for player in bsObject.find("tbody",class_ = "notranslate").find_all("a"):
        all_players = "https://www.mlb.com" + player.get("href")
        soup = get_object(all_players)
        data = get_all_summary_career(soup)
        
        players = soup.find(class_ = "full-name").text 
        born = list(soup.find("div", class_ = "player-header--vitals").text)
        players_list = list(filter(None,players.split("Fullname:")))
        lista_players.append(players_list)
        choice = st.sidebar.selectbox("Escolha o Jogador:", lista_players)

        if choice :
            st.dataframe(data)

      
        
#streamlit run mlb.py
1 Like

Hey @Isabele_Alves_Pereir!

Bem-vindo à comunidade Streamlit! :partying_face: :partying_face: :tada: :tada: :tada:
Welcome to the Streamlit Community! :partying_face: :partying_face: :tada: :tada: :tada:

Não sei nenhum português, por isso estou usando o Google Translate para me ajudar (desculpe se é uma tradução muito ruim :laughing:)
I don’t know any Portuguese, so I am using Google Translate to help me (so sorry if its a very bad translation :laughing:)

Eu adoraria ver uma captura de tela do seu aplicativo em ação! Sinta-se à vontade para postar um aqui :blush:
I would love to see a screenshot of your app in action! Feel free to post one here :blush:

Mal posso esperar para ver o que você faz a seguir!
Can’t wait to see what you make next!

Marisa

1 Like

@Marisa_Smith : that was perfect :slight_smile:

@Isabele_Alves_Pereir : Benvinda! Eu ia responder mas a Marisa já disse tudo, haha.

2 Likes

Uploading: Foto.png…

1 Like