Scraper for basketball rosters I am very new to Python and I am trying to learn through personnal projects and today I needed to collect a lot of baksetball player names and decided this was a good time to learn and practice.
The script is able to pull out all of the players names, height, nationality and DOB but I need to enter the link to the pages before launching it.
Next step will be either to build a graphic interface where I can copy/past the links or asking in the console wether I want to enter a new team.
I am looking forward to hearing from you since this is maybe my first personnal project :)
import os
import requests
import pandas as pd
import xlsxwriter
from bs4 import BeautifulSoup

def reverse(name):
    to_reverse = name
    return ' '.join(reversed(name.split(' ')))

def conversion_df(url):
    requete = requests.get(url)
    page = requete.content
    soup = BeautifulSoup(page, features=&quot;lxml&quot;)

    header = [th.getText() for th in soup.findAll(&quot;th&quot;)]    # Why do I have to put th. before getText for it to work | Why do we use th as an updator 
    header = header[1:5] # Here we exclude the first (O) entry and we display the entries situated before 5

    row = soup.findAll(&quot;tr&quot;)[1:]
    stats = [[td.getText().strip() for td in row[i]] for i in range(len(row))]
    for j in stats: 
        del j[0]
        del j[4]
    #print(stats)

    for i in range(len(stats)):
        stats[i][0] = reverse(stats[i][0])

    table = pd.DataFrame(data = stats, columns = header)
    return table

nanterre = conversion_df(&quot;https://www.lnb.fr/fr/espa/equipe/espoirs-nanterre-61344.html&quot;)
monaco = conversion_df(&quot;https://www.lnb.fr/fr/espa/equipe/espoirs-monaco-61343.html&quot;)
boulazac = conversion_df(&quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-boulazac-61331.html&quot;)
boulogne = conversion_df(&quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-boulogne-levallois-61332.html&quot;)
bourg = conversion_df(&quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-bourg-en-bresse-61333.html&quot;)
chalon = conversion_df(&quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-chalon-saone-61334.html&quot;)
cholet = conversion_df(&quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-cholet-61336.html&quot;)
chalon_reims = conversion_df(&quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-chalons-reims-61335.html&quot;)
dijon = conversion_df(&quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-dijon-61337.html&quot;)
gravelines = conversion_df(&quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-gravelines-dunkerque-61338.html&quot;)
le_mans = conversion_df(&quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-le-mans-61339.html&quot;)
le_portel = conversion_df(&quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-le-portel-61340.html&quot;)
orleans = conversion_df(&quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-orleans-61345.html&quot;)
pau = conversion_df(&quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-pau-lacq-orthez-61346.html&quot;)
roanne = conversion_df(&quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-roanne-61347.html&quot;)
strasbourg = conversion_df(&quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-strasbourg-61348.html&quot;)
limoges = conversion_df(&quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-limoges-61341.html&quot;)
lyon = conversion_df(&quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-lyon-villeurbanne-61342.html&quot;)

clubs = [boulazac,boulogne,bourg,chalon,cholet,chalon_reims,dijon,gravelines,le_mans,le_portel,limoges,lyon,monaco,nanterre,orleans,pau,roanne,strasbourg]

# Creating Excel Writer Object from Pandas  
writer = pd.ExcelWriter('liste_espoir.xlsx',engine='xlsxwriter')   
workbook=writer.book
worksheet=workbook.add_worksheet('Espoirs')
writer.sheets['Espoirs'] = worksheet

row_count = 0
i = 0

for i in range(len(clubs)):
    clubs[i].to_excel(writer,sheet_name='Espoirs',startrow=row_count , startcol=0)   
    row_count += 20

writer.save()
Welcome to Code Review. Your code looks to be following some good practices from python's style guide (PEP-8). However, as a programmer, you can perhaps improve the structure/performance.

No need to have separate variables for dataframes for each club. Group all the links together, and use a map for fetch everything.
The reverse function defines an unused variables to_reverse.
Split functionality to separate function, just like you have one to reverse names.
You do not need to iterate over range(len(some_iterable)) if the index is not needed at all.
Add type hinting, and some comments to functions to help understand what kind of values it might expect (and return), as well as, what it is doing.
Put everything inside an if __name__ == &quot;__main__&quot; clause.


Rewritten code:
from typing import Tuple
import requests
import pandas as pd
import xlsxwriter
from bs4 import BeautifulSoup


def reverse(name: str) -&gt; str:
    &quot;&quot;&quot;Reverse name from 'Last First' to 'First Last'.&quot;&quot;&quot;
    return &quot; &quot;.join(reversed(name.split(&quot; &quot;)))


def fetch_page(url: str) -&gt; str:
    &quot;&quot;&quot;Send request to given url, and return the contents on success.&quot;&quot;&quot;
    response = requests.get(url)
    if response.ok:
        return response.content


def get_club_information(club_page) -&gt; Tuple:
    &quot;&quot;&quot;Read all `tr` elements on page, and extract player information.

    Each row (`tr`) consists of 6 cells. We are skipping over 1st and last cell data.&quot;&quot;&quot;
    soup = BeautifulSoup(club_page, features=&quot;lxml&quot;)
    rows = soup.findAll(&quot;tr&quot;)
    header, *content = [[cell.getText().strip() for cell in row][1:5] for row in rows]
    for row in content:
        row[0] = reverse(row[0])
    return header, content


def conversion_df(url):
    page = fetch_page(url)
    header, content = get_club_information(page)
    print(header, content)
    table = pd.DataFrame(data=content, columns=header)
    return table


LINKS = (
    &quot;https://www.lnb.fr/fr/espa/equipe/espoirs-nanterre-61344.html&quot;,
    &quot;https://www.lnb.fr/fr/espa/equipe/espoirs-monaco-61343.html&quot;,
    &quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-boulazac-61331.html&quot;,
    &quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-boulogne-levallois-61332.html&quot;,
    &quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-bourg-en-bresse-61333.html&quot;,
    &quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-chalon-saone-61334.html&quot;,
    &quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-cholet-61336.html&quot;,
    &quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-chalons-reims-61335.html&quot;,
    &quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-dijon-61337.html&quot;,
    &quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-gravelines-dunkerque-61338.html&quot;,
    &quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-le-mans-61339.html&quot;,
    &quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-le-portel-61340.html&quot;,
    &quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-orleans-61345.html&quot;,
    &quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-pau-lacq-orthez-61346.html&quot;,
    &quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-roanne-61347.html&quot;,
    &quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-strasbourg-61348.html&quot;,
    &quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-limoges-61341.html&quot;,
    &quot;https://www.lnb.fr/fr/espoirs/equipe/espoirs-lyon-villeurbanne-61342.html&quot;,
)


def main():
    # Creating Excel Writer Object from Pandas
    writer = pd.ExcelWriter(&quot;liste_espoir.xlsx&quot;, engine=&quot;xlsxwriter&quot;)
    workbook = writer.book
    writer.sheets[&quot;Espoirs&quot;] = workbook.add_worksheet(&quot;Espoirs&quot;)
    row_count = 0
    for club in map(conversion_df, LINKS):
        club.to_excel(writer, sheet_name=&quot;Espoirs&quot;, startrow=row_count, startcol=0)
        row_count += 20
    writer.save()


if __name__ == &quot;__main__&quot;:
    main()


Additionally, you can use asyncio to fetch those pages in parallel, to reduce the runtime for your program.