-
Notifications
You must be signed in to change notification settings - Fork 0
/
collect_data.py
28 lines (22 loc) · 1.08 KB
/
collect_data.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
import requests
import os
from bs4 import BeautifulSoup
# Dictionary assisting mapping every position to its correct 'URL' value
position_dict = {'QB': 10, 'RB': 20, 'WR': 30, 'TE': 40, 'K': 80, 'DEF': 99}
position = 'DEF'
week = '1'
# Url for fantasy points each NFL team allows to each position
url = "https://fftoday.com/stats/playerstats.php?Season=2019&GameWeek=1&PosID=" + str(position_dict[position]) + "&LeagueID=193033" + "&order_by=FFPts&sort_order=DESC"
html_headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36'}
r = requests.get(url, html_headers)
print("Request Sent...\n")
print("Request Status is %d \n" %r.status_code)
soup = BeautifulSoup(r.content, 'html.parser')
cwd = os.getcwd()
path = cwd + '/data/week' + week + '/' + position
os.makedirs(path, exist_ok = True)
print("Creating directory...\n")
html_path = path + '/' + position + "_urlrawhtml.txt"
outfile = open(html_path, "w")
outfile.write(str(soup.prettify()))
print(f"Writing raw html for position {position} to output text file...\n")