0

I am getting the player data from ESPN, but I find myself with the problem that to get each variable the waiting time is very long, how could I improve the efficiency?

players_by_temp = []
for i in range(20):
    players = []
    for j in range(len(html_table[i].find_all(class_='AnchorLink'))):
        players.append(html_table[i].find_all(class_='AnchorLink')[j].text)
    players_by_temp.append(players)
    print(i)
2
  • First of all, you could save the result of html_table[i].find_all(class_='AnchorLink') in a variable instead of doing it twice. Commented Nov 26, 2021 at 17:59
  • which sport? And what exactly are you after. You likely get everything through an api. Tell me what you are after and I can show you. Commented Nov 26, 2021 at 19:31

1 Answer 1

1
players_by_temp = []
for i in range(20):
    players = []
    for anchor in html_table[i].find_all(class_='AnchorLink'):
        players.append(anchor.text)
    players_by_temp.append(players)
    print(i)

Once you get more comfortable in Python, you would then replace the three center lines with the following:

    players = [anchor.text for anchor in html_table[i].find_all(...)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.