-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathteam_tennisrecord.py
34 lines (26 loc) · 1.11 KB
/
team_tennisrecord.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import requests
import pandas as pd
import numpy as np
from bs4 import BeautifulSoup
#Pull in team page, updating with your team's information
URL = "https://www.tennisrecord.com/adult/teamprofile.aspx?teamname=_______&year=2022&s=2"
page = requests.get(URL)
soup = BeautifulSoup(page.content, "html.parser")
#Select the players table
results_list = [table for table in soup.find_all("table", class_="responsive14")]
#Create list of players names
td_list = [table.find_all("td", class_="padding10") for table in results_list]
a_list = [td.find_all("a") for td in td_list[2]]
content = [item.text.strip() for a in a_list for item in a]
#Convert names to all caps
#content = [name.upper() for name in content]
#Remove last blank entry from list
#content.pop()
print(content)
#Create list of names in format tennisrecord.com needs
search_params = [name.replace(" ", "%20") for name in content]
print(search_params)
#Delete unnecessary local variables
del results_list, td_list, a_list
for player in search_params:
print(r'https://www.tennisrecord.com/adult/profile.aspx?playername='+ player)