0

这是我拥有的代码,它工作正常,但我怎样才能使有一个新变量等于 GIF 的图像 URL,以便用户可以获得 GIF 的源 URL?

import requests

url = "https://giphy.p.rapidapi.com/v1/gifs/search"

searchtag = input()

querystring = {"api_key":"secret_key","q":searchtag,"limit":"1","offset":"0","rating":"pg-13"}

headers = {
    'x-rapidapi-key': "4005b98f9bmsh977c629b89034a7p19b52fjsn22b7fb5ce3bb",
    'x-rapidapi-host': "giphy.p.rapidapi.com"
    }

response = requests.request("GET", url, headers=headers, params=querystring)

print(response.text)

4

1 回答 1

0

首先,为了您自己的人身安全,您可能应该删除您的 api 密钥。我建议查看环境文件以存储不属于数据库的私人信息。其次要回答您的问题,如果您愿意,可以将 url 声明为变量,在这里:

    import requests

url = "https://giphy.p.rapidapi.com/v1/gifs/search"

searchtag = input()

querystring = {"api_key":process.env.APIKEY,"q":searchtag,"limit":"1","offset":"0","rating":"pg-13"}

headers = {
    'x-rapidapi-key': "4005b98f9bmsh977c629b89034a7p19b52fjsn22b7fb5ce3bb",
    'x-rapidapi-host': "giphy.p.rapidapi.com"
    }

response = requests.request("GET", url, headers=headers, params=querystring)
gifurl = response.text
print(gifurl)
于 2021-08-05T03:04:49.497 回答