在Python中使用特定API

2024-06-26 17:50:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我对Python非常陌生(对编程也比较陌生),希望能得到任何帮助。你知道吗

如何使用下面的示例链接下载使用Python提供的信息。你知道吗

https://url.com/InfoService/GetFlightByFlightNum?board={BOARD}&flightNum={flightNum}

方法:GET

谢谢


Tags: 方法httpsboardcom信息url示例get
2条回答

您可以使用内置库urllib2。你知道吗

Python2文档:http://docs.python.org/2/library/urllib2.html

python3文档:http://docs.python.org/3.1/howto/urllib2.html

下面是一些例子:How do I download a file over HTTP using Python?

从python访问api最简单的方法是使用requests

您可以使用pip install requests快速安装它

然后你可以这样做作为你的例子:

import requests

payload = {'board': {BOARD}, 'flightNum': {FLIGHTNUM}}
r = requests.get('https://url.com/InfoService/GetFlightByFlightNum', params=payload)

# print the response result
print r.text

相关问题 更多 >