我正在尝试在我的 python 脚本中使用链接缩短服务,但是它们的 API documentation是 JSON 格式(使用curl 调用 URL)。我是初学者,所以不知道如何实现。
最佳答案
鉴于所提供文档的第一个示例,您可以简单地使用 requests
像这样的模块:
import requests
data = '{"username":"<Username or email>","password":"<Password>"}' #equal to: -d '{"url":"<Some URL>"}'
response = requests.get('https://www.capsulink.com/api/login', data=data)
其他一切都可以以此为基础构建。
编辑
使用 requests
请求缩短的链接:
import requests
header = {"Api-Key": "<Some API key>"} #equal to: -H 'Api-Key: <Some API key>'
data = '{"url": "<Some URL>"}' #equal to: -d '{"url":"<Some URL>"}'
response = requests.get('https://www.capsulink.com/api/capsulate', headers=header, data=data)
只需替换 "<Some API key>"
使用您需要的 API key 和 "<Some URL>"
以及您感兴趣的相应网址。
关于python - API:Python中使用curl调用URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58690203/