mardi 7 mai 2019

How can I scrape data from an HTML table into a Python list/dict?

I'm trying to import data from Baseball Prospectus (https://legacy.baseballprospectus.com/card/70917/trea-turner) into a Python table / dictionary (which would be better?).

Below is what I have, based on following along to Automate The Boring Stuff with Python.

I get that my method isn't properly using these functions, but I can't figure out what tools I should be using.

import requests
import webbrowser
import bs4

res = requests.get('https://legacy.baseballprospectus.com/card/70917/trea-turner')
res.raise_for_status()
webpage = bs4.BeautifulSoup(res.text)
table = webpage.select('newstat_career_log_datagrid')
list = []
for item in table:
    list.append(item)

print(list)
```




Aucun commentaire:

Enregistrer un commentaire