与Web API进行交互

这里通过一个实例来说明:获取GitHub上最新的30条关于pandas的问题

可以使用附加库requests发送一个get请求

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
29
30
31
32
33
34
35
36
37
url = 'https://api.github.com/repos/pandas-dev/pandas/issues'
resp = requests.get(url)
data = resp.json()
print(pd.DataFrame(data,columns=['number','title','labels','state'])) ==>
number ... state
0 28452 ... open
1 28451 ... open
2 28448 ... open
3 28447 ... open
4 28446 ... open
5 28444 ... open
6 28443 ... open
7 28442 ... open
8 28441 ... open
9 28440 ... open
10 28438 ... open
11 28436 ... open
12 28435 ... open
13 28434 ... open
14 28433 ... open
15 28432 ... open
16 28431 ... open
17 28430 ... open
18 28429 ... open
19 28428 ... open
20 28427 ... open
21 28426 ... open
22 28425 ... open
23 28424 ... open
24 28423 ... open
25 28422 ... open
26 28418 ... open
27 28417 ... open
28 28415 ... open
29 28414 ... open

[30 rows x 4 columns]
Author: YihangBao
Link: https://roarboil.github.io/2019/09/16/webapi/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.