替换for循环中的子字符串



我正在运行这样的API查询。代替";montratec";在这里q=montratec,我想使用我存储在列表中的各种不同的单词。我想通过用列表names中的不同元素替换单词montratec来在for循环中运行此操作。我怎样才能做到这一点?

url = "https://google-search3.p.rapidapi.com/api/v1/crawl/q=montratec%20AND%20(katalog%20OR%20catalog%20OR%20brosch%C3%BCre%20OR%20brochure)%20AND%20filetype=pdf&num=5"
response = requests.request("GET", url, headers=headers)
for i in names:
url = "https://google-search3.p.rapidapi.com/api/v1/crawl/q=montratec%20AND%20(katalog%20OR%20catalog%20OR%20brosch%C3%BCre%20OR%20brochure)%20AND%20filetype=pdf&num=5" 

尝试以下操作(使用"f"字符串(

for name in names:
url = f"https://google-search3.p.rapidapi.com/api/v1/crawl/q={name}%20AND%20(katalog%20OR%20catalog%20OR%20brosch%C3%BCre%20OR%20brochure)%20AND%20filetype=pdf&num=5" 

最新更新