我正在尝试使用多处理来提高抓取的速度,但是我不知道如何将其集成到我的代码中。
我正在使用Python 3.7
import requests as r
import pandas as pd
pd.DataFrame(data=None, index=None, columns=None, dtype=None, copy=False)
team_ids = [100, 200, 300, 400, 500]
d = {'player_id' : [],
'num' : [],
'name' : []
}
for t_ in team_ids:
url = 'http://example_url?team_id='+str(t_)
req = r.get(url)
json = req.json()
team_id = t_
for rs in json['team_names']['Results']['row']:
d['player_id'].append(rs['player_id'])
d['num'].append(rs['jersey_number'])
d['name'].append(rs['name_last_first'])
tabla = pd.DataFrame(d)