Skip to content

Instantly share code, notes, and snippets.

@databyjp
Created August 26, 2020 11:41
Show Gist options
  • Select an option

  • Save databyjp/82457c051fd152033af5345e79fc301d to your computer and use it in GitHub Desktop.

Select an option

Save databyjp/82457c051fd152033af5345e79fc301d to your computer and use it in GitHub Desktop.
data_rows = table.find_all("tr", attrs={"class": "team"}) # Includes the header row!
parsed_data = list()
stat_keys = [col.attrs["class"][0] for col in data_rows[0].find_all("td")]
for row in data_rows:
tmp_data = dict()
for attr in stat_keys:
attr_val = row.find(attrs={"class": attr}).text
tmp_data[attr] = re.sub(r"^\s+|\s+$", "", attr_val)
parsed_data.append(tmp_data)
data_df = pd.DataFrame(parsed_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment