我正在尝试使用特定的搜索查询从Github API中提取数据并将其放入一个.txt文件中。我可以通过curl和shell来实现这一点,但是我需要用python来实现,我对python非常陌生。我看过请求库
我试过用这个网站
https://curl.trillworks.com/
使用请求库,但我似乎无法理解如何格式化请求。
curl -H "Authorization: token xxx" 'https://api.github.com' "https://github.com/api/v3/search/repositories?q=Evidence+locker+Seed+in:readme" > evidencelockerevidence.txt
上面的代码正是我需要它做的事情(传递ghe令牌、调用api、将其存储在一个文件中),我只需要转换成python的帮助。
编辑:解决方案是
import requests
headers = {
'Authorization': 'token xxx',
}
url = 'https://github.ibm.com/api/v3/search/repositories?q=Evidence+locker+Seed+in:readme'
response = requests.get(url, headers=headers)
print(response)
print(response.text)