Last active
December 8, 2023 14:31
-
-
Save bdilday/6e6bef77a5e42776a7e6da7bee12178d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup | |
from pybaseball.league_batting_stats import get_table, session | |
START_DT = "2021-05-02" | |
def fetch_date(dt): | |
url = ( | |
"http://www.baseball-reference.com/leagues/daily.cgi?" | |
"user_team=&bust_cache=&type=b&lastndays=7&dates=fromandto&" | |
f"fromandto={START_DT}.{dt}&level=mlb&franch=" | |
"&stat=&stat_value=0" | |
) | |
print(url) | |
s = session.get(url).content | |
return s | |
def get_soccer_link(soup): | |
link = soup.find_all("a")[7] | |
print(link) | |
return link | |
def has_german_language_link(soup): | |
return "fbref.com/de/" in get_soccer_link(soup).decode() | |
def main(): | |
for end_day in range(2, 10): | |
end_dt = f"2021-05-{end_day:02d}" | |
s = fetch_date(end_dt) | |
soup = BeautifulSoup(s) | |
if has_german_language_link(soup): | |
table = get_table(soup) | |
print(table) | |
return | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment